Regression (Incorrect utcoffset returned from timezones)

Bug #1324158 reported by Justin Wood (Callek)
18
This bug affects 3 people
Affects Status Importance Assigned to Milestone
pytz
Invalid
Undecided
Unassigned

Bug Description

This is a regression of launchpad bug #310606.

It regressed between pytz==2014.1 and pytz==2014.3

Working code:
datetime.datetime(2011, 6, 27, 2, 0, 0, tzinfo=pytz.timezone("US/Pacific")).strftime('%Y-%m-%d %H:%M:%S %Z%z')
'2011-06-27 02:00:00 PST-0800'

Failing code:
datetime.datetime(2011, 6, 27, 2, 0, 0, tzinfo=pytz.timezone("US/Pacific")).strftime('%Y-%m-%d %H:%M:%S %Z%z')
'2011-06-27 02:00:00 LMT-0753'

pytz.timezone("US/Pacific")
<DstTzInfo 'US/Pacific' LMT-1 day, 16:07:00 STD>

... c.f. the external pull request where we discovered this issue: https://github.com/mozilla/build-relengapi/pull/72

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

Per the README, you need to use the following method to construct a localized datetime:

>>> import pytz
>>> pytz.__version__
'2014.3'
>>> import datetime
>>> pytz.timezone("US/Pacific").localize(datetime.datetime(2011, 6, 27, 2, 0, 0)).strftime('%Y-%m-%d %H:%M:%S %Z%z')
'2011-06-27 02:00:00 PDT-0700'

Note that your original working code is not actually working, as it is reporting standard time when that timestamp is in the daylight savings time period starting 13th March 2011. What you are retrieving is the first timezone period stored in the database. Lots of early timezone transitions were added in 2013c.

Changed in pytz:
status: New → Invalid
Revision history for this message
Abhishek Singh (abhi-20dec) wrote :

I am still getting the error. i am using pytz 2014-04

import pytz
import dateutil.parser
TZINFOS = {
     'PDT': pytz.timezone('US/Pacific-New'),
}
datestring = '03:10:00 Jul 26, 2014 PDT'
datetime_in_pdt = dateutil.parser.parse(datestring, tzinfos= TZINFOS)
datetime_in_utc = datetime_in_pdt.astimezone(pytz.utc)
datetime_naive = datetime_in_utc.replace(tzinfo = None)
print datetime_in_pdt
2014-07-26 03:10:00-07:53

print datetime_in_utc
2014-07-26 11:03:00+00:00

Revision history for this message
Ben (a03e1as2s-ben-chgtaa3qp) wrote :

I was bit by this as well on an update, seems like the intuitive datetime to associate a naive tz should be "now", and that intuition is grounded in it working that way for as long as I can remember. This is somewhat aggravated by the annual versioning which doesn't have a "major revision" for breaking changes to be introduced, but that's perhaps tangential.

Revision history for this message
Bernhard M. Wiedemann (ubuntubmw) wrote :

also discussed in bug 1319939

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

Duplicates of this bug

Other bug subscribers

Remote bug watches

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