|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[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
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Fri Oct 24 18:00:01 2025 UTC |
Also does not return a time zone for Indian Standard Time: timezone_name_from_abbr('', 19800, 0)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.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; } }<?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!!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