From c1411e65b77af791e2e4a795a0c1e9beac63a41e Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Fri, 21 Mar 2014 10:13:29 +0100 Subject: [PATCH] Fix: Try to add code to provide easy way to fix warning on timezone not defined. --- htdocs/core/lib/functions.lib.php | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/htdocs/core/lib/functions.lib.php b/htdocs/core/lib/functions.lib.php index ae1b91ef712..bf398c389c0 100644 --- a/htdocs/core/lib/functions.lib.php +++ b/htdocs/core/lib/functions.lib.php @@ -987,9 +987,9 @@ function dol_getdate($timestamp,$fast=false) * @param int $month Month (1 to 12) * @param int $day Day (1 to 31) * @param int $year Year - * @param int $gm 1=Input informations are GMT values, otherwise local to server TZ + * @param int $gm true or 1=Input informations are GMT values, false or 0 or 'server' = local to server TZ, 'user' = local to user TZ * @param int $check 0=No check on parameters (Can use day 32, etc...) - * @return int Date as a timestamp, '' if error + * @return int Date as a timestamp, '' if error * @see dol_print_date, dol_stringtotime, dol_getdate */ function dol_mktime($hour,$minute,$second,$month,$day,$year,$gm=false,$check=1) @@ -1015,9 +1015,21 @@ function dol_mktime($hour,$minute,$second,$month,$day,$year,$gm=false,$check=1) if (method_exists('DateTime','getTimestamp') && empty($conf->global->MAIN_OLD_DATE)) { - if (empty($gm)) + if (empty($gm) || $gm === 'server') { - $default_timezone=@date_default_timezone_get(); + // If you can't set timezone of your PHP, set this constant. Better is to set it to UTC. + // In future, this constant will be forced to 'UTC' so PHP server timezone will not have effect anymore. + if (! empty($conf->global->MAIN_SERVER_TZ)) + { + if ($conf->global->MAIN_SERVER_TZ != 'auto') $default_timezone=$conf->global->MAIN_SERVER_TZ; + else $default_timezone=@date_default_timezone_get(); + } + else $default_timezone=@date_default_timezone_get(); + $localtz = new DateTimeZone($default_timezone); + } + else if ($gm === 'user') + { + $default_timezone=(empty($_SESSION["dol_tz_string"])?'UTC':$_SESSION["dol_tz_string"]); $localtz = new DateTimeZone($default_timezone); } else $localtz = new DateTimeZone('UTC');