David (dblume) wrote,

python : don't trust time.altzone

Ran into a little trouble with Python's time module. TZ is not set on my system. Everything works, except for time.altzone, it's not in sync with the other time methods. I'd expected altzone to be the same as the difference between my time and gmtime.
>>> import time
>>> time.tzname
('Pacific Standard Time', 'Pacific Daylight Time')
>>> time.daylight
>>> time.altzone # "Only use this if daylight is nonzero."
>>> time.mktime(time.gmtime()) - time.mktime(time.localtime())
>>> time.localtime() # The last number should be 0 == not DST
(2006, 2, 2, 12, 31, 0, 3, 33, 0)
>>> time.localtime(1154549697.0) # The last number should be 1 == DST
(2006, 8, 2, 13, 14, 57, 2, 214, 1)
Tags: programming, python

  • Progress on my Google+ and LJ backups

    Since Google is going to shut down Google+, I decided it was time to really make a home for my LiveJournal backup and my Google+ backup. Working…

  • Getting Shit Done

    I came across an old LifeHacker article Get Shit Done Blocks Distracting Web Sites So You Can Do As the Name Instructs, that mentions a productivity…

  • Fifth Grade Homework - Nine digit pandigital prime number

    Yesterday my daughter in the fifth grade got the following homework assignment "arrange the digits one through nine into a nine-digit prime number."…

  • Post a new comment


    Comments allowed for friends only

    Anonymous comments are disabled in this journal

    default userpic

    Your reply will be screened

    Your IP address will be recorded