Why does the following happen?
from datetime import datetime
import pytz
d = pytz.utc.localize(datetime.utcnow())
print float(d.strftime('%s')) - float(d.replace(tzinfo=None).strftime('%s')) # 3600.0
Why is it off by one hour whether or not tzinfo is included? I'm assuming it has to do with DST, but... UTC does not have DST.
d.timetuple()
# time.struct_time(tm_year=2013, tm_mon=10, tm_mday=21, tm_hour=17, tm_min=44, tm_sec=40, tm_wday=0, tm_yday=294, tm_isdst=0)
d.replace(tzinfo=None).timetuple()
# time.struct_time(tm_year=2013, tm_mon=10, tm_mday=21, tm_hour=17, tm_min=44, tm_sec=40, tm_wday=0, tm_yday=294, tm_isdst=-1)
So, the difference is tm_isdst
is 0
or -1
. Both seem very "No DST-ish".
Just not thrilled with the workaround.
Update:
After reading some docs (http://docs.python.org/2/library/time.html#time.mktime) It appears mktime()
outputs "localtime" not UTC as I had thought. Which confuses everything.