example = datetime.datetime(2014, 8, 19, 14, 18, 49, 435413, tzinfo=psycopg2.tz.FixedOffsetTimezone(offset=-240, name=None))
datetime.datetime.fromtimestamp(time.mktime(example.timetuple()))
datetime.datetime(2014, 8, 19, 15, 18, 49)
You can see that when I construct example
, it's 14:18 (2:18 pm). When I convert it to a utc epoch, then back again, it's 15:18 (3:18 pm).
I'm using psycopg2's FixedOffsetTimezone
because this row value comes from a database.
Trying to do everything in UTC yields even more confusing results.
datetime.datetime.utcfromtimestamp(time.mktime(example.utctimetuple()))
datetime.datetime(2014, 8, 19, 23, 18, 49)
In my first example, where is my extra hour coming? I suspect daylight saving time, DST, but my machine (and Python) yield the correct dates:
datetime.datetime.now()
datetime.datetime(2014, 8, 19, 14, 49, 21, 2429)
And from the shell:
> date
Tue Aug 19 14:49:49 EDT 2014