|
@@ -658,125 +658,11 @@ function api_format_date($time, $format = null, $language = null)
|
|
|
* @author Julio Montoya
|
|
|
*/
|
|
|
|
|
|
-function date_to_str_ago($date)
|
|
|
+function date_to_str_ago($date, $timeZone = 'UTC')
|
|
|
{
|
|
|
- static $initialized = false;
|
|
|
- static $today, $yesterday;
|
|
|
- static $min_decade, $min_year, $min_month, $min_week, $min_day, $min_hour, $min_minute;
|
|
|
- static $min_decades, $min_years, $min_months, $min_weeks, $min_days, $min_hours, $min_minutes;
|
|
|
- static $sec_time_time, $sec_time_sing, $sec_time_plu;
|
|
|
+ $timeAgo = new TimeAgo($timeZone, api_get_language_isocode());
|
|
|
|
|
|
- $system_timezone = date_default_timezone_get();
|
|
|
- date_default_timezone_set(_api_get_timezone());
|
|
|
-
|
|
|
- if (!$initialized) {
|
|
|
- $today = get_lang('Today');
|
|
|
- $yesterday = get_lang('Yesterday');
|
|
|
-
|
|
|
- $min_decade = get_lang('MinDecade');
|
|
|
- $min_year = get_lang('MinYear');
|
|
|
- $min_month = get_lang('MinMonth');
|
|
|
- $min_week = get_lang('MinWeek');
|
|
|
- $min_day = get_lang('MinDay');
|
|
|
- $min_hour = get_lang('MinHour');
|
|
|
- $min_minute = get_lang('MinMinute');
|
|
|
-
|
|
|
- $min_decades = get_lang('MinDecades');
|
|
|
- $min_years = get_lang('MinYears');
|
|
|
- $min_months = get_lang('MinMonths');
|
|
|
- $min_weeks = get_lang('MinWeeks');
|
|
|
- $min_days = get_lang('MinDays');
|
|
|
- $min_hours = get_lang('MinHours');
|
|
|
- $min_minutes = get_lang('MinMinutes');
|
|
|
-
|
|
|
- // original 1
|
|
|
- //$sec_time=array('century'=>3.1556926*pow(10,9),'decade'=>315569260,'year'=>31556926,'month'=>2629743.83,'week'=>604800,'day'=>86400,'hour'=>3600,'minute'=>60,'second'=>1);
|
|
|
- //$sec_time=array(get_lang('MinDecade')=>315569260,get_lang('MinYear')=>31556926,get_lang('MinMonth')=>2629743.83,get_lang('MinWeek')=>604800,get_lang('MinDay')=>86400,get_lang('MinHour')=>3600,get_lang('MinMinute')=>60);
|
|
|
- $sec_time_time = array(315569260, 31556926, 2629743.83, 604800, 86400, 3600, 60);
|
|
|
- $sec_time_sing = array($min_decade, $min_year, $min_month, $min_week, $min_day, $min_hour, $min_minute);
|
|
|
- $sec_time_plu = array($min_decades, $min_years, $min_months, $min_weeks, $min_days, $min_hours, $min_minutes);
|
|
|
- $initialized = true;
|
|
|
- }
|
|
|
-
|
|
|
- $dst_date = is_string($date) ? strtotime($date) : $date;
|
|
|
- // For avoiding calling date() several times
|
|
|
- $date_array = date('s/i/G/j/n/Y', $dst_date);
|
|
|
- $date_split = explode('/', $date_array);
|
|
|
-
|
|
|
- $dst_s = $date_split[0];
|
|
|
- $dst_m = $date_split[1];
|
|
|
- $dst_h = $date_split[2];
|
|
|
- $dst_day = $date_split[3];
|
|
|
- $dst_mth = $date_split[4];
|
|
|
- $dst_yr = $date_split[5];
|
|
|
-
|
|
|
- $dst_date = mktime($dst_h, $dst_m, $dst_s, $dst_mth, $dst_day, $dst_yr);
|
|
|
- $time = $offset = time() - $dst_date; // Seconds between current days and today.
|
|
|
-
|
|
|
- // Here start the functions sec_to_str()
|
|
|
- $act_day = date('d');
|
|
|
- $act_mth = date('n');
|
|
|
- $act_yr = date('Y');
|
|
|
-
|
|
|
- if ($dst_day == $act_day && $dst_mth == $act_mth && $dst_yr == $act_yr) {
|
|
|
- return $today;
|
|
|
- }
|
|
|
-
|
|
|
- if ($dst_day == $act_day - 1 && $dst_mth == $act_mth && $dst_yr == $act_yr) {
|
|
|
- return $yesterday;
|
|
|
- }
|
|
|
-
|
|
|
- $str_result = array();
|
|
|
- $time_result = array();
|
|
|
- $key_result = array();
|
|
|
-
|
|
|
- $str = '';
|
|
|
- $i = 0;
|
|
|
- for ($i = 0; $i < count($sec_time_time); $i++) {
|
|
|
- $seconds = $sec_time_time[$i];
|
|
|
- if ($seconds > $time) {
|
|
|
- continue;
|
|
|
- }
|
|
|
- $current_value = intval($time/$seconds);
|
|
|
-
|
|
|
- if ($current_value != 1) {
|
|
|
- $date_str = $sec_time_plu[$i];
|
|
|
- } else {
|
|
|
- $date_str = $sec_time_sing[$i];
|
|
|
-
|
|
|
- }
|
|
|
- $key_result[] = $sec_time_sing[$i];
|
|
|
-
|
|
|
- $str_result[] = $current_value.' '.$date_str;
|
|
|
- $time_result[] = $current_value;
|
|
|
- $str .= $current_value.$date_str;
|
|
|
- $time %= $seconds;
|
|
|
- }
|
|
|
-
|
|
|
- if (!empty($key_result)) {
|
|
|
- if ($key_result[0] == $min_day && $key_result[1]== $min_minute) {
|
|
|
- $key_result[1] = ' 0 '.$min_hours;
|
|
|
- $str_result[0] = $time_result[0].' '.$key_result[0];
|
|
|
- $str_result[1] = $key_result[1];
|
|
|
- }
|
|
|
-
|
|
|
- if ($key_result[0] == $min_year && ($key_result[1] == $min_day || $key_result[1] == $min_week)) {
|
|
|
- $key_result[1] = ' 0 '.$min_months;
|
|
|
- $str_result[0] = $time_result[0].' '.$key_result[0];
|
|
|
- $str_result[1] = $key_result[1];
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- if (!empty($str_result)) {
|
|
|
- if (!empty($str_result[1])) {
|
|
|
- $str = $str_result[0].', '.$str_result[1];
|
|
|
- } else {
|
|
|
- $str = $str_result[0];
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- date_default_timezone_set($system_timezone);
|
|
|
- return $str;
|
|
|
+ return $timeAgo->inWords($date);
|
|
|
}
|
|
|
|
|
|
/**
|