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

2012年6月05日 10:43:59 -0700

On Tue, Jun 5, 2012 at 10:21 AM, Alexander Belopolsky
<[email protected]> wrote:
> On Tue, Jun 5, 2012 at 9:45 AM, Guido van Rossum <[email protected]> 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).total_seconds()
What do they want to set the dst flag for?
> You seem to advocate for
>
>  def utctimestamp(self):
>      return (self - _EPOCH).total_seconds()
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)
_______________________________________________
Python-Dev mailing list
[email protected]
http://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com

Reply via email to