Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ability to get Olson/POSIX name of a timezone #76

Open
aschatten opened this issue Apr 9, 2015 · 6 comments
Open

Add ability to get Olson/POSIX name of a timezone #76

aschatten opened this issue Apr 9, 2015 · 6 comments

Comments

@aschatten
Copy link

I want to save a timezone name in the database, so maybe it would be nice to have an ability to get Olson or POSIX name of the timezone.
Example:

>>> from dateutil import tz
>>> tzla = tz.gettz('America/Los_Angeles')
>>> print tzla.name
America/Los_Angeles
>>> tzla = tz.gettz('America/Los Angeles')
>>> print tzla.name
America/Los_Angeles
>>> tzmet = tz.gettz('MET')
>>> print tzla.name
MET

Please let me know what you think? I can try to implement this.

@pganssle
Copy link
Member

pganssle commented Apr 9, 2015

This seems reasonable. Feel free to make a pull request. One thing I'd be a bit worried about is cross-platform compatibility here. You can probably pull it from the filename, but on *nix systems, I'm getting:

    >>> from dateutil import tz
    >>> tzla = tz.gettz('America/Los_Angeles')
    >>> print(tzla._filename)
    '/usr/share/zoneinfo/America/Los_Angeles'
    >>> tzmet = tz.gettz('MET')
    >>> print(tzmet._filename)
    '/usr/share/zoneinfo/MET'

Whereas on Windows I'm getting:

    >>> from dateutil import tz
    >>> tzla = tz.gettz('America/Los_Angeles')
    >>> print(tzla._filename)
    'America/Los_Angeles'
    >>> tzmet = tz.gettz('MET')
    >>> print(tzmet._filename)
    'MET'

I'm guessing this is because on the *nix systems it's using the system zoneinfo file, and on Windows it's using the one provided by dateutil. If you decide not to make a PR, I can dig into this later.

@systemcatch
Copy link

Hey @pganssle I had a go at implementing this.

(dateutil) chris@ThinkPad:~/dateutil$ python
Python 3.8.3 (default, Jul  7 2020, 18:57:36) 
[GCC 9.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from dateutil import tz
>>> nyc=tz.gettz("America/New_York")
>>> nyc
tzfile('/usr/share/zoneinfo/America/New_York')
>>> nyc.zone_name
'America/New_York'

It's currently exposed on tzfile, let me know if that's acceptable and I can make a full PR. Otherwise I'll dig into the codebase more to find another way of doing it.

@jorisvandenbossche
Copy link

@systemcatch I would be interested in this functionality. Do you still have your implementation lying around? (and want to make a PR?)

@systemcatch
Copy link

Hey @jorisvandenbossche I will take a look but I have a feeling that local branch may be gone.

@pganssle
Copy link
Member

pganssle commented Aug 5, 2021

At this point it's probably easiest to wait for #1130 to be done, and/or use zoneinfo.Zoneinfo, which exposes this information.

@jorisvandenbossche
Copy link

@pganssle thanks for that pointer, looking forward to that change then. About using zoneinfo.Zoneinfo instead, certainly agree that one should prefer that if possible, but for context: my question was triggered by https://issues.apache.org/jira/browse/ARROW-5248, where we would like to support dateutil timezone objects in pyarrow (so if our users (or pandas users) are still using dateutil instead of zoneinfo).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants