Bug (??) in the time module?

Paul Watson pwatson at redlinepy.com
Tue Jun 17 11:01:47 EDT 2003


 I get the same result using Python 2.2.2 on Linux.  However, I get a
different result using 2.3.b1 on Windows 2000.  If you are going to persist
a timestamp, it might be a good idea to write it in UTC.  Using ISO 8601
format might be a good idea as well.

C:\src\python\t>cat tim.py
#! /usr/bin/python

import time

thetime = time.time()
timeString = time.ctime(thetime)
print timeString
timeTuple = time.strptime(timeString)
print timeTuple
thetime2 = time.mktime(timeTuple)
timeString2 = time.ctime(thetime2)
print timeString2

C:\src\python\t>tim.py
Tue Jun 17 09:48:01 2003
(2003, 6, 17, 9, 48, 1, 1, 168, -1)
Tue Jun 17 09:48:01 2003


"Anoop Aryal" <aryal at ameritech.net> wrote in message
news:_wuHa.4165$87.2880721 at newssrv26.news.prodigy.com...
> Hi,
> i'm not sure if this is the right place to post it. if it's not, i would
> appriciate it if you could point me to the right newsgroup.
>
> i had needed to do some time manipulation -- take the unix time value,
> convert it to localtime (human readable format), save it to a text file.
> later, read it from the text file, convert it back to unix time format
> for comparisions. it seems that in this round trip, i'm ahead by an
> hour. i'm guessing it's got something to do with daylight savings. but
> here's the code that illustrates the problem:
> ---------------------------
> #!/usr/bin/python
>
> import time
>
> thetime = time.time()
> timeString = time.ctime(thetime)
> print timeString
> timeTuple = time.strptime(timeString)
> print timeTuple
> thetime2 = time.mktime(timeTuple)
> timeString2 = time.ctime(thetime2)
> print timeString2
>
> -----------------------------
> and here's the output i get:
>
> Mon Jun 16 10:45:50 2003
> (2003, 6, 16, 10, 45, 50, 0, 167, 0)
> Mon Jun 16 11:45:50 2003
>
> ----------------------------
>
> i'm on python 2.2.2 on an up2dated rh9.
>
> i've used localtime() etc in place of ctime(). but can't figure this one
> out. it's good up to the tuple returned by strptime(). i would assume
> that both mktime() and  ctime() (i think the culprit here is mktime())
> would 'do the right thing' without extensive parameter passing for this
> type of default conversions... it this a bug?
>
> thanks,
> anoop
> aryal at ameritech.net
>






More information about the Python-list mailing list