[Python-Dev] TZ-aware local time

Alexander Belopolsky alexander.belopolsky at gmail.com
Wed Jun 6 03:17:46 CEST 2012


On Tue, Jun 5, 2012 at 8:18 PM, Barry Warsaw <barry at python.org> wrote:
>> I think stdlib should allow me to write
>>a robust application that knows that some naive datetime objects
>>correspond to two points in time and some correspond to none.
>
> Really?  Why would naive datetimes know that?  I would expect that an aware
> datetime would have that information but not naive ones.

I did not say that it is the datetime objects who would have that
information.  It is the application or the library that should embody
such knowledge.  So if I try to specify time as 2012-03-11 at 2:30 AM
"New York time," the application should know that no such time exists
and reject it as it would 2012-03-11 at 2:66 AM.

At the end of the day, users want an easy way to solve the equation

datetime.fromtimestamp(x) = dt,

but this equation can have 0, 1 or 2 solutions depending on the value
of dt.  An ultimate solution would be to provide a function that
returns a list length 0, 1, or 2.  Short of that, we can assume
standard time when there are two solutions and raise an exception when
there are none.  This is the math.sqrt() approach.


More information about the Python-Dev mailing list