forked from Wavyzz/dolibarr
Fix timezone problem with external calendar import.
This commit is contained in:
@@ -962,7 +962,8 @@ function dol_strftime($fmt, $ts=false, $is_gmt=false)
|
||||
* "day", "daytext", "dayhour", "dayhourldap", "dayhourtext", "dayrfc", "dayhourrfc"
|
||||
* @param string $tzoutput true or 'gmt' => string is for Greenwich location
|
||||
* false or 'tzserver' => output string is for local PHP server TZ usage
|
||||
* 'tzuser' => output string is for local browser TZ usage
|
||||
* 'tzuser' => output string is for user TZ (current browser TZ with current dst)
|
||||
* 'tzuserrel' => output string is for user TZ (current browser TZ with dst or not, depending on date position)
|
||||
* @param Translate $outputlangs Object lang that contains language for text translation.
|
||||
* @param boolean $encodetooutput false=no convert into output pagecode
|
||||
* @return string Formated date or '' if time is null
|
||||
@@ -984,19 +985,17 @@ function dol_print_date($time,$format='',$tzoutput='tzserver',$outputlangs='',$e
|
||||
if ($tzoutput == 'tzserver')
|
||||
{
|
||||
$to_gmt=false;
|
||||
$offsettz=$offsetdst=0;
|
||||
$offsettzstring=@date_default_timezone_get(); // Example 'Europe/Berlin' or 'Indian/Reunion'
|
||||
$offsettz=0;
|
||||
$offsetdst=0;
|
||||
}
|
||||
elseif ($tzoutput == 'tzuser')
|
||||
{
|
||||
$to_gmt=true;
|
||||
$offsettzstring=(empty($_SESSION['dol_tz_string'])?'UTC':$_SESSION['dol_tz_string']); // Example 'Europe/Berlin' or 'Indian/Reunion'
|
||||
$offsettz=(empty($_SESSION['dol_tz'])?0:$_SESSION['dol_tz'])*60*60;
|
||||
$offsetdst=(empty($_SESSION['dol_dst'])?0:$_SESSION['dol_dst'])*60*60;
|
||||
}
|
||||
elseif ($tzoutput == 'tzcompany')
|
||||
{
|
||||
$to_gmt=false;
|
||||
$offsettz=$offsetdst=0; // TODO Define this and use it later
|
||||
}
|
||||
}
|
||||
}
|
||||
if (! is_object($outputlangs)) $outputlangs=$langs;
|
||||
@@ -1045,9 +1044,9 @@ function dol_print_date($time,$format='',$tzoutput='tzserver',$outputlangs='',$e
|
||||
$format=str_replace('%A','__A__',$format);
|
||||
}
|
||||
|
||||
// Analyze date (deprecated) Ex: 1970-01-01, 1970-01-01 01:00:00, 19700101010000
|
||||
// Analyze date
|
||||
if (preg_match('/^([0-9]+)\-([0-9]+)\-([0-9]+) ?([0-9]+)?:?([0-9]+)?:?([0-9]+)?/i',$time,$reg)
|
||||
|| preg_match('/^([0-9][0-9][0-9][0-9])([0-9][0-9])([0-9][0-9])([0-9][0-9])([0-9][0-9])([0-9][0-9])$/i',$time,$reg))
|
||||
|| preg_match('/^([0-9][0-9][0-9][0-9])([0-9][0-9])([0-9][0-9])([0-9][0-9])([0-9][0-9])([0-9][0-9])$/i',$time,$reg)) // Deprecated. Ex: 1970-01-01, 1970-01-01 01:00:00, 19700101010000
|
||||
{
|
||||
// This part of code should not be used. TODO Remove this.
|
||||
dol_syslog("Functions.lib::dol_print_date function call with deprecated value of time in page ".$_SERVER["PHP_SELF"], LOG_WARNING);
|
||||
@@ -1067,7 +1066,7 @@ function dol_print_date($time,$format='',$tzoutput='tzserver',$outputlangs='',$e
|
||||
// Date is a timestamps
|
||||
if ($time < 100000000000) // Protection against bad date values
|
||||
{
|
||||
$ret=adodb_strftime($format,$time+$offsettz+$offsetdst,$to_gmt); // TODO Remove this
|
||||
$ret=adodb_strftime($format,$time+$offsettz+$offsetdst,$to_gmt); // TODO Replace this with function Date PHP. We also should not use anymore offsettz and offsetdst but only offsettzstring.
|
||||
}
|
||||
else $ret='Bad value '.$time.' for date';
|
||||
}
|
||||
@@ -1198,13 +1197,13 @@ function dol_mktime($hour,$minute,$second,$month,$day,$year,$gm=false,$check=1)
|
||||
{
|
||||
if (empty($gm) || $gm === 'server')
|
||||
{
|
||||
$default_timezone=@date_default_timezone_get();
|
||||
$default_timezone=@date_default_timezone_get(); // Example 'Europe/Berlin'
|
||||
$localtz = new DateTimeZone($default_timezone);
|
||||
}
|
||||
else if ($gm === 'user')
|
||||
{
|
||||
// We use dol_tz_string first because it contains dst.
|
||||
$default_timezone=(empty($_SESSION["dol_tz_string"])?@date_default_timezone_get():$_SESSION["dol_tz_string"]);
|
||||
// We use dol_tz_string first because it is more reliable.
|
||||
$default_timezone=(empty($_SESSION["dol_tz_string"])?@date_default_timezone_get():$_SESSION["dol_tz_string"]); // Example 'Europe/Berlin'
|
||||
try {
|
||||
$localtz = new DateTimeZone($default_timezone);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user