[Python-Dev] TZ-aware local time

Guido van Rossum guido at python.org
Wed Jun 6 05:14:45 CEST 2012


On Tue, Jun 5, 2012 at 6:31 PM, Glyph <glyph at twistedmatrix.com> wrote:
>
> Le Jun 5, 2012 à 6:16 PM, Nick Coghlan a écrit :
>
> Personally, I'd like to see the datetime module make an explicit
> assumption that "all naive datetime objects are considered to be UTC",
> with the interactions between naive and aware objects updated
> accordingly
>
> I would absolutely love it if this were true.  In fact, I would go a step
> further and say that the whole concept of a "naive" datetime is simply a
> bug.  We don't have a "naive" unicode, for example, where it's text in some
> encoding but you decline to decide which one when you decode it, leaving
> that to the caller.
>
> When we addresed this problem for ourselves at Divmod some time ago,
> naive=UTC is exactly what we did:
>
> <http://bazaar.launchpad.net/~divmod-dev/divmod.org/trunk/files/head:/Epsilon/epsilon/extime.py>

You can try to enforce this, but users will ignore it, and happily
represent local time as UTC. I've seen people do this with POSIX
timestamps too -- use the UTC conversions between timestamps and time
tuples, and yet use time tuples to represent local time (the
timestamps are stored because integers are easier to store). And yes
they get in horrible trouble around DST and they don't understand why.
But they still do it.

I think it's better to give users the rope they want than to try and
prevent them from hanging themselves, since otherwise they'll just use
the power cords as ropes and electrocute themselves.

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


More information about the Python-Dev mailing list