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() {
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
38 if ($identifiers === null) {
39 $identifiers = DateTimeZone
::listIdentifiers();
40 $identifiers = array_fuse($identifiers);
43 if (isset($identifiers[$value])) {
49 'Timezone "%s" is not a valid timezone identifier.',
53 protected function getSelectOptionGroups() {
54 $timezones = DateTimeZone
::listIdentifiers();
55 $now = new DateTime('@'.PhabricatorTime
::getNow());
58 foreach ($timezones as $timezone) {
59 $zone = new DateTimeZone($timezone);
60 $offset = ($zone->getOffset($now) / 60);
61 $groups[$offset][] = $timezone;
66 $option_groups = array(
68 'label' => pht('Default'),
73 foreach ($groups as $offset => $group) {
74 $hours = $offset / 60;
75 $minutes = abs($offset %
60);
78 $label = pht('UTC%+d:%02d', $hours, $minutes);
80 $label = pht('UTC%+d', $hours);
86 foreach ($group as $identifier) {
87 $name = PhabricatorTime
::getTimezoneDisplayName($identifier);
88 $group_map[$identifier] = $name;
91 $option_groups[] = array(
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
105 $this->newSettingTransaction(
107 PhabricatorTimezoneIgnoreOffsetSetting
::SETTINGKEY
,