From cf05a924de1b92c790dfb6a39b11c87f71c24272 Mon Sep 17 00:00:00 2001 From: Aleksander Machniak Date: Fri, 23 Nov 2018 19:05:38 +0100 Subject: [PATCH] Fix inconsistent offset for various time zones - always display Standard Time offset (#6531) --- CHANGELOG | 1 + program/steps/settings/func.inc | 36 ++++++++++++++++++++++++++------- 2 files changed, 30 insertions(+), 7 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index 97c4d3d7a..851844fdf 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -41,6 +41,7 @@ CHANGELOG Roundcube Webmail - Fix custom logo size in Elastic (#6424) - Fix listing the same attachment multiple times on forwarded messages - Fix bug where a message/rfc822 part without a filename wasn't listed on the attachments list (#6494) +- Fix inconsistent offset for various time zones - always display Standard Time offset (#6531) RELEASE 1.4-beta ---------------- diff --git a/program/steps/settings/func.inc b/program/steps/settings/func.inc index 169a71b82..a279ad7e4 100644 --- a/program/steps/settings/func.inc +++ b/program/steps/settings/func.inc @@ -207,14 +207,9 @@ function rcmail_user_prefs($current = null) $zones = array(); foreach (DateTimeZone::listIdentifiers() as $i => $tzs) { - try { - $tz = new DateTimeZone($tzs); - $date = new DateTime(date('Y') . '-12-21', $tz); - $offset = $date->format('Z') + 45000; - $sortkey = sprintf('%06d.%s', $offset, $tzs); - $zones[$sortkey] = array($tzs, $date->format('P')); + if ($data = rcmail_timezone_standard_time_data($tzs)) { + $zones[$data['key']] = array($tzs, $data['offset']); } - catch (Exception $e) {} } ksort($zones); @@ -1479,3 +1474,30 @@ function rcmail_timezone_label($tz) return implode('/', $tokens); } + +/** + * Returns timezone offset in standard time + */ +function rcmail_timezone_standard_time_data($tzname) +{ + try { + $tz = new DateTimeZone($tzname); + $date = new DateTime(null, $tz); + $count = 12; + + // Move back for a month (up to 12 times) until non-DST date is found + while ($count > 0 && $date->format('I')) { + $date->sub(new DateInterval('P1M')); + $count--; + } + + $offset = $date->format('Z') + 45000; + $sortkey = sprintf('%06d.%s', $offset, $tzname); + + return array( + 'key' => $sortkey, + 'offset' => $date->format('P'), + ); + } + catch (Exception $e) {} +}