[Python-Dev] Issue 2736: datetimes and Unix timestamps (original) (raw)

Guido van Rossum guido at python.org
Tue Jun 5 19:41:40 CEST 2012


On Tue, Jun 5, 2012 at 10:21 AM, Alexander Belopolsky <alexander.belopolsky at gmail.com> wrote:

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.

Maybe you need to get out more. :-) This is how datetime is represented in App Engine's datastore: https://developers.google.com/appengine/docs/python/datastore/typesandpropertyclasses#DateTimeProperty (Note: These docs are unclear about whether a tzinfo attribute is present. The code is clear that it isn't.)

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).totalseconds()

What do they want to set the dst flag for?

You seem to advocate for

 def utctimestamp(self):  return (self - EPOCH).totalseconds()

Not literally, because this would crash when self.tzinfo is None.

I think I am advocating for the former but without the dst flag.

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

Is this an accurate summary?

-- --Guido van Rossum (python.org/~guido)



More information about the Python-Dev mailing list