Code review comment for lp:~nskaggs/autopilot/fix-1328600

Revision history for this message
Nicholas Skaggs (nskaggs) wrote :

So the idea of using tzlocal seems to suffer from daylight savings problem, unless I'm missing something.

>>> from datetime import datetime, time, timedelta
>>> from dateutil.tz import tzlocal, tzutc
>>> print(datetime.fromtimestamp(1377209927))
2013-08-22 18:18:47
>>> print(datetime.fromtimestamp(1377209927,tzutc()))
2013-08-22 22:18:47+00:00
>>> naive = datetime.fromtimestamp(0) + timedelta(seconds=1377209927)
>>> print(naive)
2013-08-22 17:18:47
>>> aware = naive.replace(tzinfo=tzlocal())
>>> print(aware)
2013-08-22 17:18:47-04:00
>>> print(aware.astimezone(tzutc()))
2013-08-22 21:18:47+00:00
>>> aware2 = datetime.fromtimestamp(0, tzlocal())
>>> print(aware2)
1969-12-31 19:00:00-05:00
>>> print(aware2.astimezone(tzutc()))
1970-01-01 00:00:00+00:00
>>> try2 = aware2 + timedelta(seconds=1377209927)
>>> print(try2)
2013-08-22 17:18:47-04:00
>>> print(try2.astimezone(tzutc()))
2013-08-22 21:18:47+00:00

« Back to merge proposal