Caught out by daylight saving :-(

CinnamonDonkey CinnamonDonkey at
Mon Mar 30 13:47:25 CEST 2009

Hi All,

I had the following bit of code which was working fine until we went
into Daylight saving this weekend, now the result is an hour out.

    timeString = "20090330 15:45:23"

    timeFormat = '%Y-%m-%d %H:%M:%S'

    modificationTime = datetime.datetime.utcfromtimestamp( time.mktime
( time.strptime( timeString, timeFormat ) ) )
    minutesToAdvance = datetime.timedelta( minutes=5 )

    modificationTime = modificationTime + minutesToAdvance

    datetimeString = str ( modificationTime ).replace( ' ', 'T' )

The expected result should be:

    datetimeString = "20090330T15:50:23"

But instead I get:

    datetimeString = "20090330T14:50:23"

I believe it is going wrong at either the mktime() or utcfromtimestamp
() stage.

What is the correct way to fix this compensating for daylight saving

SHaun >8)

More information about the Python-list mailing list