php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #44780 some time zone offsets not recognized by timezone_name_from_abbr
Submitted: 2008-04-18 20:46 UTC Modified: 2016-09-29 13:05 UTC
Votes:34
Avg. Score:4.6 ± 0.8
Reproduced:29 of 30 (96.7%)
Same Version:8 (27.6%)
Same OS:13 (44.8%)
From: shawn dot parker at alttech dot com Assigned: derick (profile)
Status: Closed Package: Date/time related
PHP Version: 5CVS-2008-08-14 OS: *
Private report: No CVE-ID: None
 [2008-04-18 20:46 UTC] shawn dot parker at alttech dot com
Description:
------------
timezone_name_from_abbr() will return false on some time zone 
offsets. In particular - Hawaii, which has a -10 from GMT offset, -36000 
seconds.

Using Denver's offset, -21600 works fine, as do most offsets, but 
occasionally offsets don't return correctly.

Reproduce code:
---------------
var_dump( timezone_name_from_abbr('',-36000,1) );

Expected result:
----------------
A time zone, like maybe 'Pacific/Honolulu'

Actual result:
--------------
false

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2008-04-18 21:11 UTC] shawn dot parker at alttech dot com
Just a quick note - this time a year, for my time zone, that should return Anchorage (or something else in the AHST time zone) because of DST.
 [2008-08-14 19:47 UTC] jani@php.net
Assigned to the date/time guru.
 [2008-11-05 19:34 UTC] mfburdett at gmail dot com
Also does not return a time zone for Indian Standard Time: timezone_name_from_abbr('', 19800, 0)
 [2008-11-06 18:27 UTC] jjkd at jjkd dot com
In my testing, this is the list of offsets that do not work for PHP 5.2.6:

-34200, ckhst
-16200, ant
-12600, negt
-7200, addt
12600, irst
16200, aft
19800, ist
20700, npt
21600, aktst
23400, burt
28800, bnt
34200, cast
35100, cwst
37800, cst
39600, anat
41400, lhst
46800, anast
49500, chadt
50400, anast
 [2008-11-06 20:22 UTC] mfburdett at gmail dot com
Note some of the above abbreviations are obsolete, e.g. BURT has been replaced with MMT.  But the point is timezone_name_from_abbr() does not work for those offsets without an abbreviation.
 [2008-11-07 17:25 UTC] mfburdett at gmail dot com
Looking at http://cvs.php.net/viewvc.cgi/php-src/ext/date/lib/fallbackmap.h?revision=1.3&view=markup it appears to be a simple bug: lookups of the fallbackmap are not working for any of the time zones with non-integer offsets.  A more minor issue (in terms of affected population size) is that some valid offsets are missing from the fallbackmap.
 [2008-11-07 17:33 UTC] mfburdett at gmail dot com
The affected population sizes of the two issues may be similar after all: China standard time is missing from the fallbackmap (offset 8 hours, daylight saving time 0).
 [2008-11-07 18:13 UTC] mfburdett at gmail dot com
The originally filed reproduce code
var_dump( timezone_name_from_abbr('',-36000,1) );
and expected result 'Pacific/Honolulu' are not actually valid because Honolulu does not observe daylight saving time.  See comments above for what look like actual bugs.
 [2009-05-08 18:23 UTC] mfburdett at gmail dot com
I was able to resolve this by changing the fallbackmap from hours to minutes (the bug is apparently due to some issue with float vs. integer).  Also, this patch adds Caracas and Shanghai time (there are likely other missing time zones, however) and uses the new spelling for Calcutta (Kolkata).

Index: ext/date/lib/fallbackmap.h
===================================================================
RCS file: /repository/php-src/ext/date/lib/fallbackmap.h,v
retrieving revision 1.3
diff -u -p -r1.3 fallbackmap.h
--- ext/date/lib/fallbackmap.h	15 Oct 2005 18:14:40 -0000	1.3
+++ ext/date/lib/fallbackmap.h	8 May 2009 18:18:32 -0000
@@ -1,40 +1,42 @@
-	{ "sst",   0,  -11,  "Pacific/Apia" },
-	{ "hst",   0,  -10,  "Pacific/Honolulu" },
-	{ "akst",  0,   -9,  "America/Anchorage" },
-	{ "akdt",  1,   -8,  "America/Anchorage" },
-	{ "pst",   0,   -8,  "America/Los_Angeles" },
-	{ "pdt",   1,   -7,  "America/Los_Angeles" },
-	{ "mst",   0,   -7,  "America/Denver" },
-	{ "mdt",   1,   -6,  "America/Denver" },
-	{ "cst",   0,   -6,  "America/Chicago" },
-	{ "cdt",   1,   -5,  "America/Chicago" },
-	{ "est",   0,   -5,  "America/New_York" },
-	{ "edt",   1,   -4,  "America/New_York" },
-	{ "ast",   0,   -4,  "America/Halifax" },
-	{ "adt",   1,   -3,  "America/Halifax" },
-	{ "brt",   0,   -3,  "America/Sao_Paulo" },
-	{ "brst",  1,   -2,  "America/Sao_Paulo" },
-	{ "azost", 0,   -1,  "Atlantic/Azores" },
-	{ "azodt", 1,    0,  "Atlantic/Azores" },
-	{ "gmt",   0,    0,  "Europe/London" },
-	{ "bst",   1,    1,  "Europe/London" },
-	{ "cet",   0,    1,  "Europe/Paris" },
-	{ "cest",  1,    2,  "Europe/Paris" },
-	{ "eet",   0,    2,  "Europe/Helsinki" },
-	{ "eest",  1,    3,  "Europe/Helsinki" },
-	{ "msk",   0,    3,  "Europe/Moscow" },
-	{ "msd",   1,    4,  "Europe/Moscow" },
-	{ "gst",   0,    4,  "Asia/Dubai" },
-	{ "pkt",   0,    5,  "Asia/Karachi" },
-	{ "ist",   0,  5.5,  "Asia/Calcutta" },
-	{ "npt",   0, 5.75,  "Asia/Katmandu" },
-	{ "yekt",  1,    6,  "Asia/Yekaterinburg" },
-	{ "novst", 1,    7,  "Asia/Novosibirsk" },
-	{ "krat",  0,    7,  "Asia/Krasnoyarsk" },
-	{ "krast", 1,    8,  "Asia/Krasnoyarsk" },
-	{ "jst",   0,    9,  "Asia/Tokyo" },
-	{ "est",   0,   10,  "Australia/Melbourne" },
-	{ "cst",   1, 10.5,  "Australia/Adelaide" },
-	{ "est",   1,   11,  "Australia/Melbourne" },
-	{ "nzst",  0,   12,  "Pacific/Auckland" },
-	{ "nzdt",  1,   13,  "Pacific/Auckland" },
+	{ "sst",   0, -660, "Pacific/Apia" },
+	{ "hst",   0, -600, "Pacific/Honolulu" },
+	{ "akst",  0, -540, "America/Anchorage" },
+	{ "akdt",  1, -480, "America/Anchorage" },
+	{ "pst",   0, -480, "America/Los_Angeles" },
+	{ "pdt",   1, -420, "America/Los_Angeles" },
+	{ "mst",   0, -420, "America/Denver" },
+	{ "mdt",   1, -360, "America/Denver" },
+	{ "cst",   0, -360, "America/Chicago" },
+	{ "cdt",   1, -300, "America/Chicago" },
+	{ "est",   0, -300, "America/New_York" },
+	{ "vet",   0, -270, "America/Caracas" },
+	{ "edt",   1, -240, "America/New_York" },
+	{ "ast",   0, -240, "America/Halifax" },
+	{ "adt",   1, -180, "America/Halifax" },
+	{ "brt",   0, -180, "America/Sao_Paulo" },
+	{ "brst",  1, -120, "America/Sao_Paulo" },
+	{ "azost", 0,  -60, "Atlantic/Azores" },
+	{ "azodt", 1,    0, "Atlantic/Azores" },
+	{ "gmt",   0,    0, "Europe/London" },
+	{ "bst",   1,   60, "Europe/London" },
+	{ "cet",   0,   60, "Europe/Paris" },
+	{ "cest",  1,  120, "Europe/Paris" },
+	{ "eet",   0,  120, "Europe/Helsinki" },
+	{ "eest",  1,  180, "Europe/Helsinki" },
+	{ "msk",   0,  180, "Europe/Moscow" },
+	{ "msd",   1,  240, "Europe/Moscow" },
+	{ "gst",   0,  240, "Asia/Dubai" },
+	{ "pkt",   0,  300, "Asia/Karachi" },
+	{ "ist",   0,  330, "Asia/Kolkata" },
+	{ "npt",   0,  345, "Asia/Katmandu" },
+	{ "yekt",  1,  360, "Asia/Yekaterinburg" },
+	{ "novst", 1,  420, "Asia/Novosibirsk" },
+	{ "krat",  0,  420, "Asia/Krasnoyarsk" },
+	{ "cst",   0,  480, "Asia/Shanghai" },
+	{ "krast", 1,  480, "Asia/Krasnoyarsk" },
+	{ "jst",   0,  540, "Asia/Tokyo" },
+	{ "est",   0,  600, "Australia/Melbourne" },
+	{ "cst",   1,  630, "Australia/Adelaide" },
+	{ "est",   1,  660, "Australia/Melbourne" },
+	{ "nzst",  0,  720, "Pacific/Auckland" },
+	{ "nzdt",  1,  780, "Pacific/Auckland" },
Index: ext/date/lib/parse_date.c
===================================================================
RCS file: /repository/php-src/ext/date/lib/parse_date.c,v
retrieving revision 1.102
diff -u -p -r1.102 parse_date.c
--- ext/date/lib/parse_date.c	10 Mar 2009 23:39:11 -0000	1.102
+++ ext/date/lib/parse_date.c	8 May 2009 18:18:32 -0000
@@ -719,7 +719,7 @@ const static timelib_tz_lookup_table* zo
 	/* Still didn't find anything, let's find the zone solely based on
 	 * offset/isdst then */
 	for (fmp = timelib_timezone_fallbackmap; fmp->name; fmp++) {
-		if ((fmp->gmtoffset * 3600) == gmtoffset && fmp->type == isdst) {
+		if ((fmp->gmtoffset * 60) == gmtoffset && fmp->type == isdst) {
 			return fmp;
 		}
 	}
Index: ext/date/lib/parse_date.re
===================================================================
RCS file: /repository/php-src/ext/date/lib/parse_date.re,v
retrieving revision 1.92
diff -u -p -r1.92 parse_date.re
--- ext/date/lib/parse_date.re	18 Dec 2008 14:54:51 -0000	1.92
+++ ext/date/lib/parse_date.re	8 May 2009 18:18:32 -0000
@@ -717,7 +717,7 @@ const static timelib_tz_lookup_table* zo
 	/* Still didn't find anything, let's find the zone solely based on
 	 * offset/isdst then */
 	for (fmp = timelib_timezone_fallbackmap; fmp->name; fmp++) {
-		if ((fmp->gmtoffset * 3600) == gmtoffset && fmp->type == isdst) {
+		if ((fmp->gmtoffset * 60) == gmtoffset && fmp->type == isdst) {
 			return fmp;
 		}
 	}
 [2011-05-30 23:51 UTC] theogaden at gmail dot com
I have the exact same problem and I found this bug entry thanks to someone at 
stackoverflow. Here was my original question: 
http://stackoverflow.com/questions/6180892/why-does-timezone-name-from-abbr-
return-an-empty-string

Test Code
------------------------------
$offset = -10; //UM10
echo timezone_name_from_abbr('', $offset * 3600, true); //empty string

Expected Result
------------------------------
Pacific/Honolulu

Actual result:
------------------------------
false

I am using PHP 5.3.0.
 [2013-01-18 13:13 UTC] ivo dot tijan at gmail dot com
<?php $timezoneName = timezone_name_from_abbr("", 28800, false); ?>

Fatal error: Uncaught exception 'Exception' with message 'DateTimeZone::__construct() [<a href='datetimezone.--construct'>datetimezone.--construct</a>]: Unknown or bad timezone ()' in C:\ ... \test.php:46 Stack trace: #0 C:\ ... \test.php(46): DateTimeZone->__construct('') #1 {main} thrown in C:\ ... \test.php on line 46

I am using PHP 5.3.6 MSVC9 (Visual C++ 2008).

It is January 2013 and this bug is still around, even though 23 out of 24 current votes reproduced the bug!!
 [2014-01-25 15:16 UTC] derick@php.net
Automatic comment on behalf of github@derickrethans.nl
Revision: http://git.php.net/?p=php-src.git;a=commit;h=e6ab180394f4d6fe2f0a50887b098af24a3d765c
Log: Fixed bug #44780: some time zone offsets not recognized by timezone_name_from_abbr.
 [2014-01-25 15:16 UTC] derick@php.net
-Status: Assigned +Status: Closed
 [2014-01-25 15:17 UTC] derick@php.net
Automatic comment on behalf of github@derickrethans.nl
Revision: http://git.php.net/?p=php-src.git;a=commit;h=e6ab180394f4d6fe2f0a50887b098af24a3d765c
Log: Fixed bug #44780: some time zone offsets not recognized by timezone_name_from_abbr.
 [2014-01-25 15:17 UTC] derick@php.net
Automatic comment on behalf of github@derickrethans.nl
Revision: http://git.php.net/?p=php-src.git;a=commit;h=e6ab180394f4d6fe2f0a50887b098af24a3d765c
Log: Fixed bug #44780: some time zone offsets not recognized by timezone_name_from_abbr.
 [2014-01-25 15:17 UTC] derick@php.net
Automatic comment on behalf of github@derickrethans.nl
Revision: http://git.php.net/?p=php-src.git;a=commit;h=e6ab180394f4d6fe2f0a50887b098af24a3d765c
Log: Fixed bug #44780: some time zone offsets not recognized by timezone_name_from_abbr.
 [2014-01-26 04:25 UTC] ab@php.net
Automatic comment on behalf of github@derickrethans.nl
Revision: http://git.php.net/?p=php-src.git;a=commit;h=e6ab180394f4d6fe2f0a50887b098af24a3d765c
Log: Fixed bug #44780: some time zone offsets not recognized by timezone_name_from_abbr.
 [2014-02-12 08:46 UTC] tyrael@php.net
Automatic comment on behalf of github@derickrethans.nl
Revision: http://git.php.net/?p=php-src.git;a=commit;h=e6ab180394f4d6fe2f0a50887b098af24a3d765c
Log: Fixed bug #44780: some time zone offsets not recognized by timezone_name_from_abbr.
 [2014-03-12 14:14 UTC] arjen at react dot com
This issue isn't mentioned in the 5.5.10 changelog @ http://www.php.net/ChangeLog-5.php#5.5.10

Same for #45543

Following scripts shows the difference between 5.5.9 and 5.5.10: 
http://3v4l.org/1qPqL

Not sure which of these bugs causes this change, but I think it's worth mentioning in these changelog...
 [2014-04-12 10:16 UTC] dhaval007sisodiya at gmail dot com
I use following code to get timezone name:  
$timezoneOffset = "05:30";
echo $timezone_name = timezone_name_from_abbr("",$timezoneOffset*3600,0);

but it's output is : Asia/Karachi
Expected output: Asia/Kolkata
 [2014-10-07 23:16 UTC] stas@php.net
Automatic comment on behalf of github@derickrethans.nl
Revision: http://git.php.net/?p=php-src-security.git;a=commit;h=e6ab180394f4d6fe2f0a50887b098af24a3d765c
Log: Fixed bug #44780: some time zone offsets not recognized by timezone_name_from_abbr.
 [2014-10-07 23:27 UTC] stas@php.net
Automatic comment on behalf of github@derickrethans.nl
Revision: http://git.php.net/?p=php-src-security.git;a=commit;h=e6ab180394f4d6fe2f0a50887b098af24a3d765c
Log: Fixed bug #44780: some time zone offsets not recognized by timezone_name_from_abbr.
 [2015-10-29 18:43 UTC] jeff at moreactive dot com
This is still an issue as of PHP 5.5.27

PHP 5.5.27 (cli) (built: Jul 23 2015 00:21:59)
Copyright (c) 1997-2015 The PHP Group
Zend Engine v2.5.0, Copyright (c) 1998-2015 Zend Technologies


As this shows closed, what version is this supposedly fixed in?
 [2016-09-29 13:05 UTC] cmb@php.net
> As this shows closed, what version is this supposedly fixed in?

This issue is fixed as of PHP 5.4.26 and 5.5.10. If you still
experience problems, please open a new ticket and provide a
reproduce script.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Nov 21 12:01:29 2024 UTC