regebro / tzlocal

A Python module that tries to figure out what your local timezone is
MIT License
184 stars 58 forks source link

`localize` is Gone in Latest Release #113

Closed souch3 closed 2 years ago

souch3 commented 2 years ago

localize was able to be called to interpret a naive datetime as the local time zone. With the latest release, that call raises an AttributeError

import tzlocal
from datetime import datetime

loc = tzlocal.get_localzone()
d = datetime.now()
loc.localize(d)

I suspect this is due to a change in the return type to being backports.zoneinfo.ZoneInfo. I believe it used to be a pytz object? I'm assuming this is behaving correctly and we should switch our code to use astimezone but confirming here

regebro commented 2 years ago

Yes, this is correct, it now uses the Python 3 standard library timezones instead of pytz.

regebro commented 2 years ago

The new 4.0b3 release uses a shim that is backwards compatible with pytz, so localize() should work there, but a with a deprecation warning.

regebro commented 2 years ago

4.0 is released, so this should no longer be an issue, I hope.