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
So the idea of using tzlocal seems to suffer from daylight savings problem, unless I'm missing something.
>>> from datetime import datetime, time, timedelta fromtimestamp( 1377209927) ) fromtimestamp( 1377209927, tzutc() )) fromtimestamp( 0) + timedelta( seconds= 1377209927) tzinfo= tzlocal( )) astimezone( tzutc() )) fromtimestamp( 0, tzlocal()) astimezone( tzutc() )) seconds= 1377209927) astimezone( tzutc() ))
>>> from dateutil.tz import tzlocal, tzutc
>>> print(datetime.
2013-08-22 18:18:47
>>> print(datetime.
2013-08-22 22:18:47+00:00
>>> naive = datetime.
>>> print(naive)
2013-08-22 17:18:47
>>> aware = naive.replace(
>>> print(aware)
2013-08-22 17:18:47-04:00
>>> print(aware.
2013-08-22 21:18:47+00:00
>>> aware2 = datetime.
>>> print(aware2)
1969-12-31 19:00:00-05:00
>>> print(aware2.
1970-01-01 00:00:00+00:00
>>> try2 = aware2 + timedelta(
>>> print(try2)
2013-08-22 17:18:47-04:00
>>> print(try2.
2013-08-22 21:18:47+00:00