strtotime() returns false for some valid timezones
| Bug #46111 | strtotime() returns false for some valid timezones | ||||
|---|---|---|---|---|---|
| Submitted: | 2008-09-18 06:01 UTC | Modified: | 2010-03-07 20:18 UTC | ||
| From: | jason at eventshop dot com dot au | Assigned: | derick (profile) | ||
| Status: | Closed | Package: | Date/time related | ||
| PHP Version: | 5.*, 6CVS (2009-05-10) | OS: | * | ||
| Private report: | No | CVE-ID: | None | ||
[2008-09-18 06:01 UTC] jason at eventshop dot com dot au
Description:
------------
When converting a date/time/timezone string using strtotime(), it returns false for several of the supposedly valid timezones, such as "Adelaide/ACT", "Israel", "US/Arizona", etc.
All other timezones work correctly.
Reproduce code:
---------------
$timezones = timezone_identifiers_list();
foreach ($timezones as $zone) {
$date_string = "2008-01-01 13:00:00 " . $zone;
if (!strtotime($date_string)) {
echo "<br />" . $zone;
}
}
Expected result:
----------------
No result should be displayed.
Actual result:
--------------
Africa/Dar_es_Salaam
Africa/Porto-Novo
America/Argentina/ComodRivadavia
America/Blanc-Sablon
... etc ...
US/Pacific
US/Pacific-New
US/Samoa
W-SU
Zulu
Patches
Pull Requests
History
AllCommentsChangesGit/SVN commits
[2009-05-10 21:19 UTC] jani@php.net
[2010-01-21 14:00 UTC] yoarvi at gmail dot com
The failures in PHP 5.3 are the following: Africa/Dar_es_Salaam Africa/Porto-Novo America/Blanc-Sablon America/Port-au-Prince America/Port_of_Spain Antarctica/DumontDUrville Antarctica/McMurdo The regex for tz in parse_date.re doesn't account for hyphens, or for lower-case following an _ or for consecutive upper case letters. Applying the following patch and regenerating parse_date.c fixes the problem: Index: ext/date/lib/parse_date.re =================================================================== --- ext/date/lib/parse_date.re (revision 293574) +++ ext/date/lib/parse_date.re (working copy) @@ -854,7 +854,7 @@ second = minute | "60"; secondlz = minutelz | "60"; meridian = ([AaPp] "."? [Mm] "."?) [\000\t ]; -tz = "("? [A-Za-z]{1,6} ")"? | [A-Z][a-z]+([_/][A-Z][a-z]+)+; +tz = "("? [A-Za-z]{1,6} ")"? | [A-Z][a-z]+([_/-][A-Za-z]+)+; tzcorrection = "GMT"? [+-] hour24 ":"? minute?; daysuf = "st" | "nd" | "rd" | "th";[2010-01-27 12:49 UTC] yoarvi at gmail dot com
[2010-01-27 14:10 UTC] derick@php.net
[2010-03-07 20:18 UTC] derick@php.net
-Status: Assigned +Status: Closed
[2010-03-07 20:18 UTC] derick@php.net