You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I can reproduce this issue but interestingly I don't have tzdata installed, also if just run the following on the command line I get the wrong time:
TZ=America/Mexico_City date
So it seems Pendulum is falling about to the locally installed database? Where as pytz is not? Perhaps someone can figure out the logic of where it's sourcing it and if it can be changed?
I'm having this issue too. I think this is happening because the last release of pendulum (2.1.2), is using the last version (from 2020) of pytzdata. The 3.0.0a prerelease of pendulum stops using pytzdata, at least for python > 3.9 and starts using built in zoneinfo. The problem is that this prerelease is not stable and has other breaking changes, so we can't use it.
I see three options:
We manually patch the zoneinfo files used by pytzdata
Maintainers of pytzdata release a new updated version
We try to make pendulum 2.1.2 stop using pytzdata as its source of timezones data
This is caused by pendulum release 2.1.2 referencing (now) obsolete IANA zoneinfo, specifically 2022.1. As a temporary fix, to force pendulum 2.1.2 to use either the system zoneinfo, or (on Windows), the zoneinfo from the first party module tzdata, put the following into your python import path as (for example) pendulum_212_fix.py, and after you import pendulum, add the line import pendulum_212_fix, and you should be good.
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
This module has one purpose - to fix the behavior of pendulum release
2.1.2, which uses a hardcoded version of the IANA zoneinfo data, 2022.2.
Importing this module after importing pendulum should cause pendulum to
use either the OS provided zoneinfo data, or if that does not exist, to
use the zoneinfo from the first party module tzdata. Note this introduces
a dependence on tzdata, which must be separetely installed, typically via
pip install tzdata.
In theory, IMMEDIATELY AFTER IMPORTING pendulum, you should simply
import this module and pendulum will then use the local system
zoneinfo, if available, and if not, the zoneinfo from tzdata, when
creating aware datetimes.
"""
import pathlib
import sysconfig
import tzdata
LOCAL_TZPATH = sysconfig.get_config_var('TZPATH')
if LOCAL_TZPATH:
# This could be a colon separated list of paths; we take the first only
LOCAL_TZPATH = LOCAL_TZPATH.split(':')[0]
else:
LOCAL_TZPATH = pathlib.Path(tzdata.__path__) / 'zoneinfo'
import pendulum
import pytzdata
pytzdata.set_directory(LOCAL_TZPATH)
if __name__ == '__main__':
pass
Activity
notatallshaw-gts commentedon Apr 3, 2023
You probably have an old timezone database on your machine: https://www.mexperience.com/mexico-set-to-abandon-seasonal-clock-time-changes/
It looks like you need at least 2022f: http://mm.icann.org/pipermail/tz-announce/2022-October/000075.html
Likely updating
tzdatato >=2022.6will fix this: https://github.com/python/tzdata/releases/tag/2022.6jpradass commentedon Apr 4, 2023
I'm having the same issue as Joaquin. With pendulum, pytz and tzdata updated to their latest versions, their giving me different results:
I double checked with the system timezone and it is fixed as it should be:
[root@521fd6d88911 /]# TZ='America/Mexico_City' date Tue Apr 4 05:28:30 CST 2023Check that Mexico_City is now on CST time frame.
notatallshaw-gts commentedon Apr 4, 2023
I can reproduce this issue but interestingly I don't have
tzdatainstalled, also if just run the following on the command line I get the wrong time:So it seems Pendulum is falling about to the locally installed database? Where as pytz is not? Perhaps someone can figure out the logic of where it's sourcing it and if it can be changed?
vxtals commentedon Apr 5, 2023
I'm having this issue too. I think this is happening because the last release of pendulum (2.1.2), is using the last version (from 2020) of pytzdata. The 3.0.0a prerelease of pendulum stops using pytzdata, at least for python > 3.9 and starts using built in zoneinfo. The problem is that this prerelease is not stable and has other breaking changes, so we can't use it.
I see three options:
vxtals commentedon Apr 5, 2023
In order to make pytzdata stop using its bundle zoneinfo data you can set this env variable:
export PYTZDATA_TZDATADIR=/usr/share/zoneinfo
so it will use the system zoneinfo data.
joaquin-casanova commentedon Apr 12, 2023
I have used this approach thanks to the advice of @vxtals
import pendulum
import pytzdata
pytzdata.set_directory("/usr/share/zoneinfo")
LOCAL_TZ_NAME = "America/Mexico_City"
LOCAL_TZ = pendulum.timezone(LOCAL_TZ_NAME)
now = pendulum.now(LOCAL_TZ)
now
alex-astronomer commentedon Apr 12, 2023
I believe that this problem is going to be very apparent for many users as Apache Airflow uses
pendulumfor time operations.apache/airflow#30605
NickFabry commentedon May 5, 2023
This is caused by pendulum release 2.1.2 referencing (now) obsolete IANA zoneinfo, specifically 2022.1. As a temporary fix, to force pendulum 2.1.2 to use either the system zoneinfo, or (on Windows), the zoneinfo from the first party module tzdata, put the following into your python import path as (for example) pendulum_212_fix.py, and after you
import pendulum, add the lineimport pendulum_212_fix, and you should be good.demxic commentedon Jul 17, 2023
Is there any other way?
Seems to me, like there is something wrong here:
LOCAL_TZPATH = pathlib.Path(tzdata.__path__) / 'zoneinfo'I have been trying all solutions provided but still can´t make America/Mexico_City timezone work.
Any other insights?
joaquin-casanova commentedon Jul 17, 2023
Well the other option is to use another time zone with the same time as Mexico_City such as America/Guatemala.
This is the last resource