From 1d73ae3b50a6a477c2328c47c60cde5d08b17712 Mon Sep 17 00:00:00 2001 From: epriestley Date: Fri, 22 Mar 2019 15:04:36 -0700 Subject: [PATCH] Fix two minor timezone display issues Summary: Ref T13263. Two minor issues: - The "reconcile" dialog shows the wrong sign because JS signs differ from normal signs (for example, PST or PDT or whatever we're in right now is shown as "UTC+7", but should be "UTC-7"). - The big dropdown of possible timezones lumps "UTC+X:30" timezones into "UTC+X". Test Plan: - Reconciled "America/Nome", saw negative UTC offsets for "America/Nome" and "America/Los_Angeles" (previously: improperly positive). - Viewed the big timzone list, saw ":30" and ":45" timezones grouped/labeled more accurately. Reviewers: amckinley Reviewed By: amckinley Maniphest Tasks: T13263 Differential Revision: https://secure.phabricator.com/D20314 --- .../PhabricatorSettingsTimezoneController.php | 5 +++++ .../settings/setting/PhabricatorTimezoneSetting.php | 13 ++++++++----- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/src/applications/settings/controller/PhabricatorSettingsTimezoneController.php b/src/applications/settings/controller/PhabricatorSettingsTimezoneController.php index 51f1747b9f..6a0ba19d03 100644 --- a/src/applications/settings/controller/PhabricatorSettingsTimezoneController.php +++ b/src/applications/settings/controller/PhabricatorSettingsTimezoneController.php @@ -113,6 +113,11 @@ final class PhabricatorSettingsTimezoneController } private function formatOffset($offset) { + // This controller works with client-side (Javascript) offsets, which have + // the opposite sign we might expect -- for example "UTC-3" is a positive + // offset. Invert the sign before rendering the offset. + $offset = -1 * $offset; + $hours = $offset / 60; // Non-integer number of hours off UTC? if ($offset % 60) { diff --git a/src/applications/settings/setting/PhabricatorTimezoneSetting.php b/src/applications/settings/setting/PhabricatorTimezoneSetting.php index 887e08129b..52fce77428 100644 --- a/src/applications/settings/setting/PhabricatorTimezoneSetting.php +++ b/src/applications/settings/setting/PhabricatorTimezoneSetting.php @@ -57,11 +57,11 @@ final class PhabricatorTimezoneSetting $groups = array(); foreach ($timezones as $timezone) { $zone = new DateTimeZone($timezone); - $offset = -($zone->getOffset($now) / (60 * 60)); + $offset = ($zone->getOffset($now) / 60); $groups[$offset][] = $timezone; } - krsort($groups); + ksort($groups); $option_groups = array( array( @@ -71,10 +71,13 @@ final class PhabricatorTimezoneSetting ); foreach ($groups as $offset => $group) { - if ($offset >= 0) { - $label = pht('UTC-%d', $offset); + $hours = $offset / 60; + $minutes = abs($offset % 60); + + if ($offset % 60) { + $label = pht('UTC%+d:%02d', $hours, $minutes); } else { - $label = pht('UTC+%d', -$offset); + $label = pht('UTC%+d', $hours); } sort($group);