From cff043a80083e14590611be6944861851b3cc42d Mon Sep 17 00:00:00 2001 From: epriestley Date: Wed, 2 Jan 2013 14:02:22 -0800 Subject: [PATCH] Validate timezones Summary: Add validation for timezones, since date_default_timezone_set() returns a usable error code. Note that we could also list all the timezones using timezone_identifiers_list(), but the list is enormous (many hundreds of entries) and impossible to use (~160 entries in "America" alone). I listed the likely US values as examples but left it as a string input text field. Test Plan: Tried to save an invalid setting. Saved a valid setting. Reviewers: codeblock, btrahan Reviewed By: btrahan CC: aran Maniphest Tasks: T2255 Differential Revision: https://secure.phabricator.com/D4318 --- .../option/PhabricatorCoreConfigOptions.php | 26 ++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/src/applications/config/option/PhabricatorCoreConfigOptions.php b/src/applications/config/option/PhabricatorCoreConfigOptions.php index 13fe3a2c94..f5c18367fa 100644 --- a/src/applications/config/option/PhabricatorCoreConfigOptions.php +++ b/src/applications/config/option/PhabricatorCoreConfigOptions.php @@ -46,7 +46,10 @@ final class PhabricatorCoreConfigOptions "possible (for instance, because you are using HPHP) you can set ". "some valid constant for date_default_timezone_set() here and ". "Phabricator will set it on your behalf, silencing the warning.")) - ->addExample('America/New_York', 'Valid Setting'), + ->addExample('America/New_York', pht('US East (EDT)')) + ->addExample('America/Chicago', pht('US Central (CDT)')) + ->addExample('America/Boise', pht('US Mountain (MDT)')) + ->addExample('America/Los_Angeles', pht('US West (PDT)')), $this->newOption('phabricator.serious-business', 'bool', false) ->setOptions( array( @@ -132,6 +135,27 @@ final class PhabricatorCoreConfigOptions $key)); } } + + + if ($key === 'phabricator.timezone') { + $old = date_default_timezone_get(); + $ok = @date_default_timezone_set($value); + @date_default_timezone_set($old); + + if (!$ok) { + throw new PhabricatorConfigValidationException( + pht( + "Config option '%s' is invalid. The timezone identifier must ". + "be a valid timezone identifier recognized by PHP, like ". + "'America/Los_Angeles'. You can find a list of valid identifiers ". + "here: %s", + $key, + 'http://php.net/manual/timezones.php')); + } + } + + + }