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

pytz library cannot localize days on boundary of representable dates #14

Open
sezal98 opened this issue Jun 7, 2018 · 2 comments
Open

Comments

@sezal98
Copy link

sezal98 commented Jun 7, 2018

Either of the following will error with an OverflowError: date value out of range:

pytz.timezone('Africa/Abidjan').localize(datetime(year=1, month=1, day=1))

OverflowError: date value out of range

pytz.timezone('Africa/Abidjan').localize(datetime(year=9999, month=12, day=31))

OverflowError: date value out of range

where as the outputs should be

datetime.datetime(1, 1, 1, 0, 0, tzinfo=<TimezoneInfo [Africa/Abidjan, LMT, -1:43:52, STD]>)

datetime.datetime(9999, 12, 31, 0, 0, tzinfo=<TimezoneInfo [Africa/Abidjan, GMT, +00:00:00, STD]>)

respectively

@sezal98
Copy link
Author

sezal98 commented Jun 7, 2018

This is because in the localize function (tzinfo.py:309 in the 2015.2 release) you look at the previous and the next day, but those might not be representable dates.

@michaeltoohig
Copy link

michaeltoohig commented Jul 14, 2021

Has there been a change due to this or still up to user to work around it?

EDIT: I found using .astimezone instead of localize was acceptable for my use case.

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

No branches or pull requests

2 participants