pytz
pytz copied to clipboard
pytz library cannot localize days on boundary of representable dates
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
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.
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.