datetime and daylight savings problem

James spiralx at gmail.com
Tue Oct 11 08:02:12 EDT 2005


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.
>>> from pytz import timezone
>>> from datetime import datetime
>>> t=timezone("Europe/Paris")
>>> utc=timezone("UTC")
>>> d=datetime(2005,01,24,16,59,tzinfo=t)
>>> d
datetime.datetime(2005, 1, 24, 16, 59, tzinfo=<DstTzInfo
'Europe/Paris' WET0:00:00 STD>)
>>> d.astimezone(utc)
datetime.datetime(2005, 1, 24, 16, 59, tzinfo=<StaticTzInfo 'UTC'>)
>>> d2=datetime(2005,06,01,16,59,tzinfo=t)
>>> d2
datetime.datetime(2005, 6, 1, 16, 59, tzinfo=<DstTzInfo 'Europe/Paris'
WET0:00:00 STD>)
>>> d2.astimezone(utc)
datetime.datetime(2005, 6, 1, 16, 59, tzinfo=<StaticTzInfo 'UTC'>)

One of these should be in DST, the other shouldn't, I'm not sure why.
Additional oddness here

>>> d.astimezone(utc).astimezone(t)
datetime.datetime(2005, 1, 24, 18, 59, tzinfo=<DstTzInfo
'Europe/Paris' CEST+2:00:00 DST>)
>>> d2.astimezone(utc).astimezone(t)
datetime.datetime(2005, 6, 1, 17, 59, tzinfo=<DstTzInfo 'Europe/Paris'
CET+1:00:00 STD>)

I'm not sure if it's just something I'm doing completely wrong here...

James



More information about the Python-list mailing list