I need to import a bunch of data into our database for which there's a
single entry each day which occurs at the same time every day in local
time - so I need to convert this to UTC taking into account local
daylight savings. However daylight savings just don't seem to be
working at all...
Python 2.3.5 (#2, May 4 2005, 08:51:39)
[GCC 3.3.5 (Debian 1:3.3.5-12)] on linux2
Type "help", "copyright" , "credits" or "license" for more information.[color=blue][color=green][color=darkred]
>>> from pytz import timezone
>>> from datetime import datetime
>>> t=timezone("Eur ope/Paris")
>>> utc=timezone("U TC")
>>> d=datetime(2005 ,01,24,16,59,tz info=t)
>>> d[/color][/color][/color]
datetime.dateti me(2005, 1, 24, 16, 59, tzinfo=<DstTzIn fo
'Europe/Paris' WET0:00:00 STD>)[color=blue][color=green][color=darkred]
>>> d.astimezone(ut c)[/color][/color][/color]
datetime.dateti me(2005, 1, 24, 16, 59, tzinfo=<StaticT zInfo 'UTC'>)[color=blue][color=green][color=darkred]
>>> d2=datetime(200 5,06,01,16,59,t zinfo=t)
>>> d2[/color][/color][/color]
datetime.dateti me(2005, 6, 1, 16, 59, tzinfo=<DstTzIn fo 'Europe/Paris'
WET0:00:00 STD>)[color=blue][color=green][color=darkred]
>>> d2.astimezone(u tc)[/color][/color][/color]
datetime.dateti me(2005, 6, 1, 16, 59, tzinfo=<StaticT zInfo 'UTC'>)
One of these should be in DST, the other shouldn't, I'm not sure why.
Additional oddness here
[color=blue][color=green][color=darkred]
>>> d.astimezone(ut c).astimezone(t )[/color][/color][/color]
datetime.dateti me(2005, 1, 24, 18, 59, tzinfo=<DstTzIn fo
'Europe/Paris' CEST+2:00:00 DST>)[color=blue][color=green][color=darkred]
>>> d2.astimezone(u tc).astimezone( t)[/color][/color][/color]
datetime.dateti me(2005, 6, 1, 17, 59, tzinfo=<DstTzIn fo 'Europe/Paris'
CET+1:00:00 STD>)
I'm not sure if it's just something I'm doing completely wrong here...
James
single entry each day which occurs at the same time every day in local
time - so I need to convert this to UTC taking into account local
daylight savings. However daylight savings just don't seem to be
working at all...
Python 2.3.5 (#2, May 4 2005, 08:51:39)
[GCC 3.3.5 (Debian 1:3.3.5-12)] on linux2
Type "help", "copyright" , "credits" or "license" for more information.[color=blue][color=green][color=darkred]
>>> from pytz import timezone
>>> from datetime import datetime
>>> t=timezone("Eur ope/Paris")
>>> utc=timezone("U TC")
>>> d=datetime(2005 ,01,24,16,59,tz info=t)
>>> d[/color][/color][/color]
datetime.dateti me(2005, 1, 24, 16, 59, tzinfo=<DstTzIn fo
'Europe/Paris' WET0:00:00 STD>)[color=blue][color=green][color=darkred]
>>> d.astimezone(ut c)[/color][/color][/color]
datetime.dateti me(2005, 1, 24, 16, 59, tzinfo=<StaticT zInfo 'UTC'>)[color=blue][color=green][color=darkred]
>>> d2=datetime(200 5,06,01,16,59,t zinfo=t)
>>> d2[/color][/color][/color]
datetime.dateti me(2005, 6, 1, 16, 59, tzinfo=<DstTzIn fo 'Europe/Paris'
WET0:00:00 STD>)[color=blue][color=green][color=darkred]
>>> d2.astimezone(u tc)[/color][/color][/color]
datetime.dateti me(2005, 6, 1, 16, 59, tzinfo=<StaticT zInfo 'UTC'>)
One of these should be in DST, the other shouldn't, I'm not sure why.
Additional oddness here
[color=blue][color=green][color=darkred]
>>> d.astimezone(ut c).astimezone(t )[/color][/color][/color]
datetime.dateti me(2005, 1, 24, 18, 59, tzinfo=<DstTzIn fo
'Europe/Paris' CEST+2:00:00 DST>)[color=blue][color=green][color=darkred]
>>> d2.astimezone(u tc).astimezone( t)[/color][/color][/color]
datetime.dateti me(2005, 6, 1, 17, 59, tzinfo=<DstTzIn fo 'Europe/Paris'
CET+1:00:00 STD>)
I'm not sure if it's just something I'm doing completely wrong here...
James
Comment