Time problem (again)

Jason Scheirer jason.scheirer at gmail.com
Thu Mar 27 16:39:20 EDT 2008


On Mar 27, 12:17 pm, "Fabio Durieux Lopes" <durieux... at yahoo.com.br>
wrote:
>    Hi,
>
>    I'm recreating a date-time based on a string and I have a problem
> when daylight savings time is set (I'm off by 1). So today I forced
> my computer into daylight savings time and debugged it again, but
> this time I noticed something strange.
>
>    This is the documentation from python library reference section
> 6.10:
>
> 6.10 time -- Time access and conversions
> ...
> daylight
> Nonzero if a DST timezone is defined.
> ...
>
> And this is what I debugged:
> -> fileTimeInSecs = time.mktime(time.strptime(timeString,
> "%Y%m%d%H%M"))
> (Pdb) p timeString
> '200803271643'
> (Pdb) n> /home/salsa/Projects/TimBR_CDR/fileSync/
>
> fileSynchronizer.py(50)passFilesOlderThan()
> -> print time.daylight
> (Pdb)
> 0
>
>  See how 'print time.daylight' resulted in '0'? Shouldn't it be Non-
> zero? Do I have to set something for it to use DST?
>
>  Also, is this the right list to send questions?

The Python datetime module's handling of time zones is completely,
entirely deficient -- the tzinfo class is just a skeleton and
therefore useless. Install something that will give you fully
implemented time zones like at http://pytz.sourceforge.net/ and try
again -- pulling a tzinfo from this module and doing
datetime_instance.replace(tzinfo=tzinfo_object_for_timezone) on your
datetime instance parsed from the string will result in far more
predictable behavior and probably get everything behaving as you
expect.



More information about the Python-list mailing list