pytz utctimetuple() produces wrong delta for Europe/London

Bug #1459314 reported by James Blackburn on 2015-05-27
10
This bug affects 2 people
Affects Status Importance Assigned to Milestone
pytz
Undecided
Unassigned

Bug Description

dt(2012, 10, 27, 12, 34, 56, 999999, tzinfo=pytz.timezone('Europe/London')).utctimetuple()
time.struct_time(tm_year=2012, tm_mon=10, tm_mday=27, tm_hour=12, tm_min=35, tm_sec=56, tm_wday=5, tm_yday=301, tm_isdst=0)
dt(2012, 10, 27, 12, 34, 56, 999999, tzinfo=pytz.timezone('Europe/London')).timetuple()
time.struct_time(tm_year=2012, tm_mon=10, tm_mday=27, tm_hour=12, tm_min=34, tm_sec=56, tm_wday=5, tm_yday=301, tm_isdst=0)

Note that the tm_min changes, but the hour doesn't... This seems to happen whatever date I provide with the Europe/London timezone.

Using pytz: pytz-2015.2 / 2015.4

And compared with tzfile:

lon_pytz = pytz.timezone('Europe/London')
lon_dtul = dateutil.tz.tzfile('/usr/share/zoneinfo/Europe/London')
d
Out[167]: datetime.datetime(2015, 10, 27, 12, 34, 56, 999999)
d.replace(tzinfo=lon_pytz).utctimetuple()
Out[168]: time.struct_time(tm_year=2015, tm_mon=10, tm_mday=27, tm_hour=12, tm_min=35, tm_sec=56, tm_wday=1, tm_yday=300, tm_isdst=0)
d.replace(tzinfo=lon_dtul).utctimetuple()
Out[169]: time.struct_time(tm_year=2015, tm_mon=10, tm_mday=27, tm_hour=12, tm_min=34, tm_sec=56, tm_wday=1, tm_yday=300, tm_isdst=0)
d.replace(tzinfo=lon_pytz).utctimetuple() == d.replace(tzinfo=lon_dtul).utctimetuple()
Out[170]: False

gcc (chris+ubuntu-qwirx) wrote :

Replacing the tzinfo is not a good idea. Calling utctimetuple() tries to translate from local time back to UTC, but clearly does so in an invalid way, not giving pytz a chance to choose the correct offset for this period in history. Note that the str(lon_pytz) is Local Mean Time, which is solar time (early timekeeping).

See http://stackoverflow.com/questions/11473721/weird-timezone-issue-with-pytz for details.

(Pdb) lon_pytz.localize(datetime(2015, 10, 27, 12, 34, 56, 999999)).utctimetuple()
time.struct_time(tm_year=2015, tm_mon=10, tm_mday=27, tm_hour=12, tm_min=34, tm_sec=56, tm_wday=1, tm_yday=300, tm_isdst=0)

(Pdb) lon_pytz.localize(datetime(2015, 9, 27, 12, 34, 56, 999999)).utctimetuple()
time.struct_time(tm_year=2015, tm_mon=9, tm_mday=27, tm_hour=11, tm_min=34, tm_sec=56, tm_wday=6, tm_yday=270, tm_isdst=0)

To post a comment you must log in.
This report contains Public information  Edit
Everyone can see this information.

Other bug subscribers