[Python-ideas] Reduce platform dependence of date and time related functions

random832 at fastmail.us random832 at fastmail.us
Tue Sep 17 21:08:49 CEST 2013


On Tue, Sep 17, 2013, at 13:29, Alexander Belopolsky wrote:
> On Tue, Sep 17, 2013 at 12:49 PM, <random832 at fastmail.us> wrote:
> 
> > 32-bit platforms are still limited by the range of
> > time_t for gmtime [and e.g. datetime.fromtimestamp],
> >
> 
> datetime.fromtimestamp() is not the same as gmtime.  You should use
> datetime.utcfromtimestamp()  which is only limited by supported date
> range
> (years 1-9999).

fromtimestamp(timestamp, timezone.utc).

And anyway, I was listing it as _another example_ of a function in
datetime which is limited by the range of time_t, not as one that is
somehow "the same as" gmtime. And even if you want to play this game,
you are WRONG WRONG WRONG about utcfromtimestamp:

Python 3.3.2 (v3.3.2:d047928ae3f6, May 16 2013, 00:06:53) [MSC v.1600 64
bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> from datetime import *
>>> datetime.utcfromtimestamp(-100000) # should be  1969-12-30 20:13:20
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
OSError: [Errno 22] Invalid argument
>>> datetime.utcfromtimestamp(2**63)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
OverflowError: timestamp out of range for platform time_t

(I don't care, per se, about 300 billion years from now, but I am 99%
certain I'd get the same result for the latter with 2**31 on 32-bit
Unix. This was to illustrate that it requires it to be in the range of
the platform time_t type.)

I feel like you're being deliberately obtuse at this point.


More information about the Python-ideas mailing list