FIX Solve problem with TZ

This commit is contained in:
Laurent Destailleur
2021-01-03 18:42:45 +01:00
parent 645b7694c9
commit b0738643fb
12 changed files with 141 additions and 155 deletions

View File

@@ -1971,10 +1971,14 @@ function dol_strftime($fmt, $ts = false, $is_gmt = false)
*
* @see dol_mktime(), dol_stringtotime(), dol_getdate()
*/
function dol_print_date($time, $format = '', $tzoutput = 'tzserver', $outputlangs = '', $encodetooutput = false)
function dol_print_date($time, $format = '', $tzoutput = 'auto', $outputlangs = '', $encodetooutput = false)
{
global $conf, $langs;
if ($tzoutput == 'auto') {
$tzoutput = $conf->tzuserinputkey;
}
// Clean parameters
$to_gmt = false;
$offsettz = $offsetdst = 0;
@@ -2184,17 +2188,23 @@ function dol_getdate($timestamp, $fast = false, $forcetimezone = '')
* @param int $year Year
* @param mixed $gm True or 1 or 'gmt'=Input informations are GMT values
* False or 0 or 'tzserver' = local to server TZ
* 'tzuser' = local to user TZ
* 'auto'
* 'tzuser' = local to user TZ taking dst into account at the current date. Not yet implemented.
* 'tzuserrel' = local to user TZ taking dst into account at the given date. Use this one to convert date input from user.
* 'tz,TimeZone' = use specified timezone
* @param int $check 0=No check on parameters (Can use day 32, etc...)
* @return int|string Date as a timestamp, '' or false if error
* @see dol_print_date(), dol_stringtotime(), dol_getdate()
*/
function dol_mktime($hour, $minute, $second, $month, $day, $year, $gm = 'tzserver', $check = 1)
function dol_mktime($hour, $minute, $second, $month, $day, $year, $gm = 'auto', $check = 1)
{
global $conf;
//print "- ".$hour.",".$minute.",".$second.",".$month.",".$day.",".$year.",".$_SERVER["WINDIR"]." -";
if ($gm == 'auto') {
$gm = $conf->tzuserinputkey;
}
// Clean parameters
if ($hour == -1 || empty($hour)) $hour = 0;
if ($minute == -1 || empty($minute)) $minute = 0;
@@ -2215,7 +2225,7 @@ function dol_mktime($hour, $minute, $second, $month, $day, $year, $gm = 'tzserve
{
$default_timezone = @date_default_timezone_get(); // Example 'Europe/Berlin'
$localtz = new DateTimeZone($default_timezone);
} elseif ($gm === 'user' || $gm === 'tzuser')
} elseif ($gm === 'user' || $gm === 'tzuser' || $gm === 'tzuserrel')
{
// 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'
@@ -2254,16 +2264,21 @@ function dol_mktime($hour, $minute, $second, $month, $day, $year, $gm = 'tzserve
/**
* Return date for now. In most cases, we use this function without parameters (that means GMT time).
*
* @param string $mode 'gmt' => we return GMT timestamp,
* @param string $mode 'auto'
* 'gmt' => we return GMT timestamp,
* 'tzserver' => we add the PHP server timezone
* 'tzref' => we add the company timezone
* 'tzuser' => we add the user timezone
* 'tzref' => we add the company timezone. Not implemented.
* 'tzuser' or 'tzuserrel' => we add the user timezone
* @return int $date Timestamp
*/
function dol_now($mode = 'gmt')
function dol_now($mode = 'auto')
{
$ret = 0;
if ($mode == 'auto') {
$mode = 'tzserver';
}
if ($mode == 'gmt') $ret = time(); // Time for now at greenwich.
elseif ($mode == 'tzserver') // Time for now with PHP server timezone added
{
@@ -2276,7 +2291,7 @@ function dol_now($mode = 'gmt')
$tzsecond=getParentCompanyTimeZoneInt(); // Contains tz+dayling saving time
$ret=dol_now('gmt')+($tzsecond*3600);
}*/
elseif ($mode == 'tzuser') // Time for now with user timezone added
elseif ($mode == 'tzuser' || $mode == 'tzuserrel') // Time for now with user timezone added
{
//print 'time: '.time();
$offsettz = (empty($_SESSION['dol_tz']) ? 0 : $_SESSION['dol_tz']) * 60 * 60;