From 5d22eeeff2b946573481983953b446326f89539a Mon Sep 17 00:00:00 2001 From: lvessiller Date: Thu, 14 Oct 2021 16:06:22 +0200 Subject: [PATCH] FIX user date timezone offset --- htdocs/core/lib/functions.lib.php | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/htdocs/core/lib/functions.lib.php b/htdocs/core/lib/functions.lib.php index e0dcc51917b..3ef328924f5 100644 --- a/htdocs/core/lib/functions.lib.php +++ b/htdocs/core/lib/functions.lib.php @@ -2284,8 +2284,17 @@ function dol_print_date($time, $format = '', $tzoutput = 'auto', $outputlangs = } elseif ($tzoutput == 'tzuser' || $tzoutput == 'tzuserrel') { $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; // Will not be used anymore - $offsetdst = (empty($_SESSION['dol_dst']) ? 0 : $_SESSION['dol_dst']) * 60 * 60; // Will not be used anymore + + if (class_exists('DateTimeZone')) { + $user_date_tz = new DateTimeZone($offsettzstring); + $user_dt = new DateTime(); + $user_dt->setTimezone($user_date_tz); + $user_dt->setTimestamp($time); + $offsettz = $user_dt->getOffset(); + } else { + $offsettz = (empty($_SESSION['dol_tz']) ? 0 : $_SESSION['dol_tz']) * 60 * 60; // Will not be used anymore + $offsetdst = (empty($_SESSION['dol_dst']) ? 0 : $_SESSION['dol_dst']) * 60 * 60; // Will not be used anymore + } } } }