time.mktime problem

Edvard Majakari edvard+news at majakari.net
Mon Sep 5 11:35:29 CEST 2005


"McBooCzech" <petr at tpc.cz> writes:


> ===snip===
> Values 100-1899 are always illegal.
> .
> .
> strptime(string[, format])
> .
> .
> The default values used to fill in any missing data are:
> (1900, 1, 1, 0, 0, 0, 0, 1, -1)
> ===snip===
>
> BTW, check the following code:
>>>import datetime, time
>>>print time.gmtime(time.mktime((1900, 1, 1, 0, 0, 0, 0, 1, -1)))
> (1901, 12, 13, 20, 45, 52, 4, 347, 0)
>
> but (1900, 1, 1, 0, 0, 0, 0, 1, -1) is (IMHO) expected.... Hmmm. But I
> am just a newbie!!! :)

You are comparing apples and oranges here. You checked documentation of
strptime, and the problem is in the use of time.mktime(). 

The point: time.mktime() returns Epoch time (seconds since 1970) and you are
passing it a tuple which is (way before) 1970. There is no such thing as
negative epoch. It is like computing packaging day of milk which hasn't been
milked from the cow yet :)

I really wonder what version of Python you are running:

>>> import datetime, time
>>> print time.gmtime(time.mktime((1900, 1, 1, 0, 0, 0, 0, 1, -1)))
Traceback (most recent call last):
  File "<stdin>", line 1, in ?
OverflowError: mktime argument out of range

Python 2.3 and 2.4 both give the same error. As for the python version 2.2, no
datetime module was implemented.

-- 
# Edvard Majakari		Software Engineer
# PGP PUBLIC KEY available    	Soli Deo Gloria!

$_ = '456476617264204d616a616b6172692c20612043687269737469616e20'; print
join('',map{chr hex}(split/(\w{2})/)),uc substr(crypt(60281449,'es'),2,4),"\n";



More information about the Python-list mailing list