php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #81083 Another way to get timezone by timeoffset from current one
Submitted: 2021-05-26 19:01 UTC Modified: 2021-06-06 04:22 UTC
From: 6562680 at gmail dot com Assigned:
Status: No Feedback Package: Date/time related
PHP Version: Irrelevant OS: Win10
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: 6562680 at gmail dot com
New email:
PHP Version: OS:

 

 [2021-05-26 19:01 UTC] 6562680 at gmail dot com
Description:
------------
If you add main geopoint in lat/lng into abbreviations list we have to sort list by diff from current one to get shortest line.

Example: you are in London (UTC). You want to get closest timezone for your clients that tell you they have +3 hours from you.

You write function like getTzOffset(int), call it like getTzOffset(5) - there you should iterate over all abbreviations.

Trying to sort result cities list could become Africa/Madagaskar (first because of alphabetical order), but i hope your clients is somewhere in Europe...

Once we have lat/lng of main point of hour line we can sort by x/y difference to get closest one.


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2021-05-26 19:23 UTC] requinix@php.net
-Summary: [ SUGGESTION ] Another way to get timezone by timeoffset from current one +Summary: Another way to get timezone by timeoffset from current one -Status: Open +Status: Feedback
 [2021-05-26 19:23 UTC] requinix@php.net
Not sure I follow.

You can already get a list of timezones with DateTimeZone::listIdentifiers() + new DateTimeZone. You can then filter that list with getOffset(the desired time).
It's pretty easy: https://3v4l.org/MTfj6

If there's one bit of room for improvement there, I'd have listIdentifiers optionally return objects instead of strings. (Or create a new method to do that.)

Stuff with coordinates (a) doesn't belong in the PHP core, not least because timezonedb is not part of PHP, and (b) doesn't even make sense because timezones are logically north-south "strips" of the planet, and the timezone "cities" used as identifiers are merely prominent locations chosen according to the rules they follow(ed) for DST transitions.
 [2021-06-06 04:22 UTC] php-bugs at lists dot php dot net
No feedback was provided. The bug is being suspended because
we assume that you are no longer experiencing the problem.
If this is not the case and you are able to provide the
information that was requested earlier, please do so and
change the status of the bug back to "Re-Opened". Thank you.
 
PHP Copyright © 2001-2021 The PHP Group
All rights reserved.
Last updated: Mon Aug 02 20:01:24 2021 UTC