pendulum icon indicating copy to clipboard operation
pendulum copied to clipboard

Unable to create timezone from shortcode

Open hussein-awala opened this issue 2 years ago • 2 comments

  • [x] I am on the latest Pendulum version.
  • [x] I have searched the issues of this repo and believe that this is not a duplicate.
  • OS version and name: Ubuntu 20.04.1
  • Pendulum version: 2.1.2

Issue

It looks like we cannot recreate a Timezone instance from all the timezones shortcodes:

>>> pendulum.timezone("Europe/Paris").tzname(dt)
'CET'
>>> pendulum.timezone("CET")
Timezone('CET')
>>> pendulum.timezone("America/New_York").tzname(dt)
'EDT'
>>> pendulum.timezone("EDT")
Traceback (most recent call last):
  File "/-env/lib/python3.11/site-packages/pendulum/tz/zoneinfo/reader.py", line 50, in read_for
    file_path = pytzdata.tz_path(timezone)
                ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/env/lib/python3.11/site-packages/pytzdata/__init__.py", line 74, in tz_path
    raise TimezoneNotFound('Timezone {} not found at {}'.format(name, filepath))
pytzdata.exceptions.TimezoneNotFound: Timezone EDT not found at /env/lib/python3.11/site-packages/pytzdata/zoneinfo/EDT

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/env/lib/python3.11/site-packages/pendulum/tz/__init__.py", line 37, in timezone
    tz = _Timezone(name, extended=extended)
         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/-env/lib/python3.11/site-packages/pendulum/tz/timezone.py", line 40, in __init__
    tz = read(name, extend=extended)
         ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/env/lib/python3.11/site-packages/pendulum/tz/zoneinfo/__init__.py", line 9, in read
    return Reader(extend=extend).read_for(name)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/env/lib/python3.11/site-packages/pendulum/tz/zoneinfo/reader.py", line 52, in read_for
    raise InvalidTimezone(timezone)
pendulum.tz.zoneinfo.exceptions.InvalidTimezone: Invalid timezone "EDT"

related: apache/airflow#34483

hussein-awala avatar Sep 19 '23 21:09 hussein-awala

@hussein-awala, hi. Try use Eastern Standard Time (EST): pendulum.timezone("EST") instead of pendulum.timezone("EDT")

issamansur avatar Sep 19 '23 21:09 issamansur

Also check this post, there are reasons why EDT and other can not in timezones

issamansur avatar Sep 19 '23 21:09 issamansur