[Python-Dev] Issue 2736: datetimes and Unix timestamps

Alexander Belopolsky alexander.belopolsky at gmail.com
Tue Jun 5 19:21:17 CEST 2012


On Tue, Jun 5, 2012 at 9:45 AM, Guido van Rossum <guido at python.org> wrote:
> TZ-less datetimes aren't going away and have
> plenty of use in contexts where the tz is either universally known or
> irrelevant.

I agree, but in these contexts naive datetime objects almost always
represent local time in some "universally known or irrelevant"
timezone.   I rarely see people use naive datetime objects to
represent UTC time and with timezone.utc added to datetime module
already the cost of supplying tzinfo to UTC datetime objects is low.

Based on tracker comments, I believe users ask for the following function:

    def timestamp(self, dst=-1):
        "Return POSIX timestamp as float"
        if self.tzinfo is None:
            return _time.mktime((self.year, self.month, self.day,
                                 self.hour, self.minute, self.second,
                                 -1, -1, dst)) + self.microsecond / 1e6
        else:
            return (self - _EPOCH).total_seconds()

You seem to advocate for

    def utctimestamp(self):
            return (self - _EPOCH).total_seconds()

in addition or instead of timestamp().  In mxDT, utctimestamp() is
called gmticks().

Is this an accurate summary?


More information about the Python-Dev mailing list