php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #73988 zone offset not recognized by timezone_name_from_abbr
Submitted: 2017-01-24 17:24 UTC Modified: 2017-01-25 11:20 UTC
From: cca dot alexk at gmail dot com Assigned:
Status: Wont fix Package: Date/time related
PHP Version: 7.0.15 OS: MacOS/Linux
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: cca dot alexk at gmail dot com
New email:
PHP Version: OS:

 

 [2017-01-24 17:24 UTC] cca dot alexk at gmail dot com
Description:
------------
timezone_name_from_abbr return false on valid time offset.
For example: Asia/Omsk has GMT+6(MSK+3) timezone, but function return false.


Test script:
---------------
var_dump( timezone_name_from_abbr("", 6*3600, false) );

Expected result:
----------------
Timezone string "Asia/Omsk"


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

Patches

timezone_name_from_abbr_omsk (last revision 2017-01-24 17:25 UTC by cca dot alexk at gmail dot com)

Add a Patch

Pull Requests

Pull requests:

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2017-01-24 17:46 UTC] derick@php.net
-Status: Open +Status: Wont fix -Type: Bug +Type: Feature/Change Request
 [2017-01-24 17:46 UTC] derick@php.net
Guessing the timezone identifier from just an abbreviation + UTCoffset + DSTenabled, is a tricky thing to do at first, as a combination is not unique.
It is even trickier to do with *just* UTCoffset + DSTenabled.

The fallback map was only really implemented to keep function parity with old PHP versions. At the time when it was written, there was no timezone that used UTC+6 (without DST), and hence, it does not have an entry. Right now for example, there could be several equally correct pickings:

derick@whisky:~ $ for i in /usr/share/zoneinfo/Asia/*; do zdump -v $i -c 2013,2018 |grep "isdst=0 gmtoff=21600"; done
/usr/share/zoneinfo/Asia/Barnaul  Sat Oct 25 19:00:00 2014 UT = Sun Oct 26 01:00:00 2014 +06 isdst=0 gmtoff=21600
/usr/share/zoneinfo/Asia/Barnaul  Sat Mar 26 19:59:59 2016 UT = Sun Mar 27 01:59:59 2016 +06 isdst=0 gmtoff=21600
/usr/share/zoneinfo/Asia/Novosibirsk  Sat Oct 25 19:00:00 2014 UT = Sun Oct 26 01:00:00 2014 NOVT isdst=0 gmtoff=21600
/usr/share/zoneinfo/Asia/Omsk  Sat Oct 25 19:00:00 2014 UT = Sun Oct 26 01:00:00 2014 OMST isdst=0 gmtoff=21600
/usr/share/zoneinfo/Asia/Tomsk  Sat Oct 25 19:00:00 2014 UT = Sun Oct 26 01:00:00 2014 +06 isdst=0 gmtoff=21600
/usr/share/zoneinfo/Asia/Tomsk  Sat May 28 19:59:59 2016 UT = Sun May 29 01:59:59 2016 +06 isdst=0 gmtoff=21600
/usr/share/zoneinfo/Asia/Yekaterinburg  Sat Oct 25 19:59:59 2014 UT = Sun Oct 26 01:59:59 2014 YEKT isdst=0 gmtoff=21600

I am reluctant to add more entries to this fallback map, and even if we would add it, I think it should be added as:

    { "novt",  0,  360, "Asia/Novosibirsk" },

To fit in with:

    { "novst", 1,  420, "Asia/Novosibirsk" },
    { "krat",  0,  420, "Asia/Krasnoyarsk" },
    { "krast", 1,  480, "Asia/Krasnoyarsk" },

Because of the non-uniqueness, I am not in favour in adding more entries.
 [2017-01-24 18:02 UTC] cca dot alexk at gmail dot com
As for the naming of zone is up to you. For me important only valid result from function.

What language capabilities I can to use for maping offset to zonename?

Of course I can build my own map, but it's better to use PHP capabilities for me.
 [2017-01-24 18:12 UTC] requinix@php.net
Related: isdst=-1 is not supported for the fallback search. https://3v4l.org/coVcm

@derick: Can the search be rewritten to work with just the main timelib_timezone_lookup map? I'm too lazy to make a patch or PR for this (let alone test it) but I'm thinking like
https://gist.github.com/requinix/dffeb6a11b278182901cd277bc5b6ba8
And I don't see anything else using timelib_timezone_fallbackmap/fallbackmap.h so they could go away.
 [2017-01-25 08:33 UTC] cca dot alexk at gmail dot com
Changed expected timezone to "Asia/Novosibirsk" in PR.
 [2017-01-25 11:20 UTC] derick@php.net
@requinix@php.net — yes, we can remove the use of the fallback map, but not in any released branch as it would be a BC break. Also note that changes to timelib need to go to https://github.com/derickr/timelib — PHP isn't the only user of this library.
 
PHP Copyright © 2001-2022 The PHP Group
All rights reserved.
Last updated: Sat May 21 23:03:34 2022 UTC