Re: OverflowError: mktime argument out of range ???

M

Michael Bentley

This is what I try:

Traceback (most recent call last):
File "<interactive input>", line 1, in <module>
OverflowError: mktime argument out of range

Probably depends on your system. It doesn't break for me:
-1294164000.0
 
J

John Machin

Probably depends on your system.

Maybe it does. It sure would be nice to get a definite answer. Pity
nobody documented the time module. Oh yeah, and the secret closed-shop
source code -- damnation! Anyone got a bootleg pirate copy of
timemodule.c lying around anywhere?
It doesn't break for me:

Please consider the possibility that it didn't break for the OP
either.
 
P

Paul Boddie

John said:
Maybe it does. It sure would be nice to get a definite answer. Pity
nobody documented the time module.

"The epoch is the point where the time starts. On January 1st of that
year, at 0 hours, the ``time since the epoch'' is zero. For Unix, the
epoch is 1970. To find out what the epoch is, look at gmtime(0)."

"The functions in this module do not handle dates and times before the
epoch or far in the future."

http://docs.python.org/lib/module-time.html

I think the consensus is that you're lucky if your system (the C
library, more specifically) lets you play with negative time values.
Here, the inquirer happens to be playing with negative time values
(under the time module's API) and should therefore consider using the
datetime module instead.

Paul
 
J

John Machin

"The epoch is the point where the time starts. On January 1st of that
year, at 0 hours, the ``time since the epoch'' is zero. For Unix, the
epoch is 1970. To find out what the epoch is, look at gmtime(0)."

"The functions in this module do not handle dates and times before the
epoch or far in the future."

http://docs.python.org/lib/module-time.html

Hypothesis 1: I must have missed that somehow!
Hypothesis 2: That page wasn't there yesterday!
Hypothesis 3: You may need to consider rebooting your irony detector.

FWIW you didn't quote what it says about the function that the OP was
calling (mktime):

"""If the input value cannot be represented as a valid time, either
OverflowError or ValueError will be raised (which depends on whether
the invalid value is caught by Python or the underlying C libraries).
The earliest date for which it can generate a time is platform-
dependent."""

Cheers,
John
 
J

Jorgen Bodde

Thanks again,

I will explain what happened. I am a python newbie. The time and
datetime modules are confusing at the beginning, but after diving into
them I started to understand the structure. So what I did was using
the time module for date storage, but I came to understand that time
is actually more used for file dates and times. That would explain the
epoch and 1970 boundaries as there are not much files before the
pre-PC era to keep timestamps for.

Basically it would have been clearer if the time module would have
been called 'filetime' as datetime kind of supercedes the time by
removing all boundaries and still presenting all methods to the user.

Onca again, it was confusing for someone starting with python, but I
think I got it now. I cannot claim it was not documented, I was more
surprised that there was a boundary and decided to ask before reading
the python docs, sorry ....

With regards,
- Jorgen
 
J

John Machin

Thanks again,

I will explain what happened. I am a python newbie.

Even GvR was a Python newbie once :)
The time and
datetime modules are confusing at the beginning, but after diving into
them I started to understand the structure. So what I did was using
the time module for date storage, but I came to understand that time
is actually more used for file dates and times. That would explain the
epoch and 1970 boundaries as there are not much files before the
pre-PC era to keep timestamps for.

Basically it would have been clearer if the time module would have
been called 'filetime' as datetime kind of supercedes the time by
removing all boundaries and still presenting all methods to the user.

The time module was intended to match the functionality of the C
standard library time.h kit, and named accordingly. The datetime
module came much later.
Onca again, it was confusing for someone starting with python, but I
think I got it now. I cannot claim it was not documented, I was more
surprised that there was a boundary and decided to ask before reading
the python docs, sorry ....

For the benefit of those who do eventually read the docs, you may like
to propose a doc patch for the time module: a sentence or two at the
start, stating that the datetime module is more suited to general data
processing than the time module.

Cheers,
John
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top