Correct a parameter order swap in "diffusion.historyquery" for Mercurial
[phabricator.git] / src / applications / settings / setting / PhabricatorTimezoneSetting.php
blob207ad95f62b05fd75d6b39c4a67c604df544c076
1 <?php
3 final class PhabricatorTimezoneSetting
4 extends PhabricatorOptionGroupSetting {
6 const SETTINGKEY = 'timezone';
8 public function getSettingName() {
9 return pht('Timezone');
12 public function getSettingPanelKey() {
13 return PhabricatorDateTimeSettingsPanel::PANELKEY;
16 protected function getSettingOrder() {
17 return 100;
20 protected function getControlInstructions() {
21 return pht('Select your local timezone.');
24 public function getSettingDefaultValue() {
25 return date_default_timezone_get();
28 public function assertValidValue($value) {
29 // NOTE: This isn't doing anything fancy, it's just a much faster
30 // validator than doing all the timezone calculations to build the full
31 // list of options.
33 if (!$value) {
34 return;
37 static $identifiers;
38 if ($identifiers === null) {
39 $identifiers = DateTimeZone::listIdentifiers();
40 $identifiers = array_fuse($identifiers);
43 if (isset($identifiers[$value])) {
44 return;
47 throw new Exception(
48 pht(
49 'Timezone "%s" is not a valid timezone identifier.',
50 $value));
53 protected function getSelectOptionGroups() {
54 $timezones = DateTimeZone::listIdentifiers();
55 $now = new DateTime('@'.PhabricatorTime::getNow());
57 $groups = array();
58 foreach ($timezones as $timezone) {
59 $zone = new DateTimeZone($timezone);
60 $offset = ($zone->getOffset($now) / 60);
61 $groups[$offset][] = $timezone;
64 ksort($groups);
66 $option_groups = array(
67 array(
68 'label' => pht('Default'),
69 'options' => array(),
73 foreach ($groups as $offset => $group) {
74 $hours = $offset / 60;
75 $minutes = abs($offset % 60);
77 if ($offset % 60) {
78 $label = pht('UTC%+d:%02d', $hours, $minutes);
79 } else {
80 $label = pht('UTC%+d', $hours);
83 sort($group);
85 $group_map = array();
86 foreach ($group as $identifier) {
87 $name = PhabricatorTime::getTimezoneDisplayName($identifier);
88 $group_map[$identifier] = $name;
91 $option_groups[] = array(
92 'label' => $label,
93 'options' => $group_map,
97 return $option_groups;
100 public function expandSettingTransaction($object, $xaction) {
101 // When the user changes their timezone, we also clear any ignored
102 // timezone offset.
103 return array(
104 $xaction,
105 $this->newSettingTransaction(
106 $object,
107 PhabricatorTimezoneIgnoreOffsetSetting::SETTINGKEY,
108 null),