Reputation: 258
If I construct a Python date, and then place it in a pytz timezone
, it behaves as expected.
x = datetime.datetime(2015,1,1,10)
z = pytz.timezone('America/Chicago')
z.localize(x)
datetime.datetime(2015, 1, 1, 10, 0, tzinfo=< DstTzInfo 'America/Chicago' CST-1 day, 18:00:00 STD >)
If I construct a Python date using a pytz timezone
as a parameter, it does not, it is (presumably) a 'sun' time with an offset for the cities distance from the time zone border.
datetime.datetime(2015,1,1,10,tzinfo=tz)
datetime.datetime(2015, 1, 1, 10, 0, tzinfo=< DstTzInfo 'America/Chicago' LMT-1 day, 18:09:00 STD >)
Is there something I can do to the date or to the timezone itself so that it behaves the same in both contexts?
Upvotes: 3
Views: 344
Reputation: 3203
The answer is directly in the pytz
docs:
Unfortunately using the tzinfo argument of the standard datetime constructors ‘’does not work’’ with pytz for many timezones.
Unless:
It is safe for timezones without daylight saving transitions though, such as UTC
Which is not your case
See: http://pythonhosted.org/pytz/
Upvotes: 2