localize() fails when offset is too large.

Bug #1490775 reported by T J
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
pytz
Invalid
Undecided
Unassigned

Bug Description

I'm playing with custom timezones, some which have an offset that exceeds 24 hours. I am able to convert UTC datetimes into these custom timezones just fine, but using localize() fails.

>>> import datetime

>>> import pytz

>>> dt = pytz.utc.localize(datetime.datetime.utcnow())

>>> dt
datetime.datetime(2015, 8, 31, 23, 30, 55, 590037, tzinfo=<UTC>)

>>> tz = pytz.timezone('Pacific/Auckland_Custom')

>>> dt.astimezone(tz)
datetime.datetime(2015, 9, 2, 4, 30, 55, 590037, tzinfo=<DstTzInfo 'Pacific/Auckland_Custom' NZST+1 day, 5:00:00 STD>)

>>> dt_local = datetime.datetime.now()

>>> tz.localize(dt_local)
.../python2.7/site-packages/pytz/tzinfo.py in localize(self, dt, is_dst)
    314 loc_dt = tzinfo.normalize(dt.replace(tzinfo=tzinfo))
    315 if loc_dt.replace(tzinfo=None) == dt:
--> 316 possible_loc_dt.add(loc_dt)
    317
    318 if len(possible_loc_dt) == 1:

ValueError: tzinfo.utcoffset() returned 1440; must be in -1439 .. 1439

Revision history for this message
Stuart Bishop (stub) wrote :

That is coming from Python's datetime library I'm afraid, and there is nothing pytz can do about it. Its documented in the tzinfo specification.

Changed in pytz:
status: New → Invalid
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.