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

M.-A. Lemburg mal at egenix.com
Thu Sep 19 10:28:15 CEST 2013

On 18.09.2013 19:37, Alexander Belopolsky wrote:
> On Wed, Sep 18, 2013 at 1:20 PM, <random832 at fastmail.us> wrote:
>> We're going around in circles. I'm proposing _removing_ those
>> limitations, so that for example code written for Unix systems (that
>> assumes it can use negative values before 1970) will work on Windows,
>> and code written for 64-bit systems will work on systems whose native
>> time_t is 32 bits.
> That's a sign that this discussion should move to the tracker where a
> concrete patch can be proposed and discussed.  There is at least one
> proposal that seems to be controversial: remove platform-dependent code
> from datetime.utcfromtimestamp().
> The change is trivial:
> def utcfromtimestamp(seconds):
>       return datetime(1970, 1, 1) + timedelta(seconds=seconds)
> I will gladly apply such patch once it is complete with tests and C code.

If you do apply this change, you will have to clearly state that
the datetime module's understanding of a timestamp may differ from
the platform definition of Unix ticks.

> The case for changing time.gmtime() is weaker.  We would have to add
> additional dependency of time module on datetime or move or duplicate a
> sizable chunk of C code.  If someone wants to undertake this project, I
> would like to see an attempt to remove circular dependency between time and
> datetime modules rather than couple the two modules even more tightly.

-1 on changing the time module APIs. People expect those to be
wrappers of the C APIs and thus also expect these APIs to
implement the platform specific behavior, e.g. supporting
leap seconds with gmtime().

POSIX called for not supporting leap seconds in e.g. gmtime(),
but they are part of the definition of GMT/UTC and it's possible
to enable support for them:


Platform comparison:


That said, it's very rare to find a system that actually
does not implement POSIX gmtime().

Marc-Andre Lemburg

Professional Python Services directly from the Source  (#1, Sep 19 2013)
>>> Python Projects, Consulting and Support ...   http://www.egenix.com/
>>> mxODBC.Zope/Plone.Database.Adapter ...       http://zope.egenix.com/
>>> mxODBC, mxDateTime, mxTextTools ...        http://python.egenix.com/
2013-09-11: Released eGenix PyRun 1.3.0 ...       http://egenix.com/go49
2013-09-20: PyCon UK 2013, Coventry, UK ...                     tomorrow
2013-09-28: PyDDF Sprint ...                                9 days to go

   eGenix.com Software, Skills and Services GmbH  Pastor-Loeh-Str.48
    D-40764 Langenfeld, Germany. CEO Dipl.-Math. Marc-Andre Lemburg
           Registered at Amtsgericht Duesseldorf: HRB 46611

More information about the Python-ideas mailing list