[Python-Dev] PEP: New timestamp formats (original) (raw)

Jeffrey Yasskin jyasskin at gmail.com
Thu Feb 2 23🔞22 CET 2012


On Wed, Feb 1, 2012 at 5:03 PM, Victor Stinner <victor.stinner at haypocalc.com> wrote:

datetime.datetime -----------------

datetime.datetime only supports microsecond resolution, but can be enhanced to support nanosecond. datetime.datetime has issues: - there is no easy way to convert it into "seconds since the epoch"

Not true:

import datetime, time epoch = datetime.datetime(1970, 1, 1, 0, 0, 0) (datetime.datetime.utcnow() - epoch).totalseconds() 1328219742.385039 time.time() 1328219747.640937

- any broken-down time has issues of time stamp ordering in the  duplicate hour of switching from DST to normal time

Only if you insist on putting it in a timezone. Use UTC, and you should be fine.

- time zone support is flaky-to-nonexistent in the datetime module

Why do you need time zone support for system interfaces that return times in UTC?

I think I saw another objection that datetime represented points in time, while functions like time.time() and os.stat() return an offset from the epoch. This objection seems silly to me: the return value of the system interfaces intends to represent points in time, even though it has to be implemented as an offset since an epoch because of limitations in C, and datetime is also implemented as an offset from an epoch (year 0).

On the other hand, the return value of functions like time.clock() is not intended to represent an exact point in time, and so should be either a timedelta or Decimal.

Jeffrey



More information about the Python-Dev mailing list