Caught out by daylight saving :-(

CinnamonDonkey CinnamonDonkey at googlemail.com
Mon Mar 30 08:55:04 EDT 2009


Ah, I think I needed to use fromtimestamp() and not utcfromtimestamp
().

:-)


On 30 Mar, 13:42, CinnamonDonkey <CinnamonDon... at googlemail.com>
wrote:
> Hi Chris,
>
> Thanx for the link... I had already found that. My problem is not
> finding information but more understanding it. I've only been
> Pythoning for a short while and I don't fully understand what the
> documentation is getting at sometimes.
>
> Is it saying that I should define a new class inheriting from tzinfo
> and refine the behaviour of the dst() function? If so, then what do I
> do with the class?
>
> On 30 Mar, 13:08, Chris <cwi... at gmail.com> wrote:
>
> > On Mar 30, 1:47 pm, CinnamonDonkey <CinnamonDon... at googlemail.com>
> > wrote:
>
> > > 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
> > > automatically?
>
> > > Regards,
> > > SHaun >8)
>
> > Take a look at the datetime docshttp://docs.python.org/library/datetime.html#datetime.tzinfo.dst
>
>




More information about the Python-list mailing list