pytz utctimetuple() produces wrong delta for Europe/London

Bug #1459314 reported by James Blackburn
10
This bug affects 2 people
Affects Status Importance Assigned to Milestone
pytz
Invalid
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.

Revision history for this message
James Blackburn (jamesblackburn) wrote :

Using pytz: pytz-2015.2 / 2015.4

Revision history for this message
James Blackburn (jamesblackburn) wrote :

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

Revision history for this message
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)

Stuart Bishop (stub)
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.