Bug #904 - Suppressing fatal errors in some timezone related functions when Chamilo runs on PHP < 5.2.

skala
Ivan Tcholakov 15 years ago
parent dc5871f762
commit c44fae9024
  1. 36
      main/inc/lib/internationalization.lib.php

@ -412,13 +412,17 @@ function api_detect_language(&$string, $encoding = null) {
* @author Guillaume Viguier <guillaume.viguier@beeznest.com>
*/
function api_get_timezones() {
if (!DATE_TIME_INSTALLED) {
// This occurs when PHP < 5.2
return array('' => '');
}
$timezone_identifiers = DateTimeZone::listIdentifiers();
sort($timezone_identifiers);
$out = array();
foreach($timezone_identifiers as $tz) {
foreach ($timezone_identifiers as $tz) {
$out[$tz] = $tz;
}
$null_option = array("" => "");
$null_option = array('' => '');
$result = array_merge($null_option, $out);
return $result;
}
@ -462,16 +466,20 @@ function api_get_utc_datetime($time = null) {
$from_timezone = _api_get_timezone();
$to_timezone = 'UTC';
if (is_null($time)) {
return gmdate("Y-m-d H:i:s");
return gmdate('Y-m-d H:i:s');
}
// If time is a timestamp, return directly in utc
if (is_int($time)) {
return gmdate("Y-m-d H:i:s", $time);
return gmdate('Y-m-d H:i:s', $time);
}
if (!DATE_TIME_INSTALLED) {
// This occurs when PHP < 5.2
return $time;
}
try {
$date = new DateTime($time, new DateTimezone($from_timezone));
$date->setTimezone(new DateTimeZone($to_timezone));
return $date->format("Y-m-d H:i:s");
return $date->format('Y-m-d H:i:s');
} catch (Exception $e) {
return null;
}
@ -486,7 +494,17 @@ function api_get_utc_datetime($time = null) {
*
* @author Guillaume Viguier <guillaume.viguier@beeznest.com>
*/
function api_get_local_time($time = null, $to_timezone=null, $from_timezone=null) {
function api_get_local_time($time = null, $to_timezone = null, $from_timezone = null) {
if (!DATE_TIME_INSTALLED) {
// This occurs when PHP < 5.2
if (is_null($time)) {
$time = time();
}
if (is_int($time)) {
$time = date('Y-m-d H:i:s', $time);
}
return $time;
}
// Determining the timezone to be converted from
if (is_null($from_timezone)) {
$from_timezone = 'UTC';
@ -627,11 +645,11 @@ function api_format_date($time, $format = null, $language = null) {
/**
* Returns the difference between the current date (date(now)) with the parameter $date in a string format like "2 days, 1 hour"
* Example: $date="2008-03-07 15:44:08";
* Example: $date = '2008-03-07 15:44:08';
* date_to_str($date) it will return 3 days, 20 hours
* The given date should be in the timezone chosen by the user or administrator. Use api_get_local_time() to get it...
*
* @param string The string has to be the result of a date function in this format -> date("Y-m-d H:i:s",time());
* @param string The string has to be the result of a date function in this format -> date('Y-m-d H:i:s', time());
* @return string The difference between the current date and the parameter in a literal way "3 days, 2 hour" *
* @author Julio Montoya
*/
@ -668,7 +686,7 @@ function date_to_str_ago($date) {
$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('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);

Loading…
Cancel
Save