Why are timezone aware and naive datetimes not distinct classes?

Adam Tauno Williams awilliam at whitemice.org
Mon Mar 11 13:27:11 EDT 2013


On Fri, 2013-03-08 at 13:41 -0500, Roy Smith wrote:
> To make a long (and painful) story short, I've got a (large) list of 
> datetimes, and was getting some bizarre errors working with it.  One of 
> the things I tried while debugging the problem was verifying that all 
> the elements of the list were indeed datetimes:
> In [59]:  set(type(foo) for foo in x)
> Out[59]:  set([datetime.datetime]

Because date/time management in Python is *@*&@R&*(R *@&Y terrible!
Period, full-stop, awful, crappy, lousy, and aggravating.  The design is
haphazard and error inducing.

Pass through the list once and convert them all the UTC [or I suppose,
make them all naive].

BTW, this page is a life and sanity saver:

<http://taaviburns.ca/what_you_need_to_know_about_datetimes/datetime_transforms.html>

And one of my own tricks is posted here:

<http://www.whitemiceconsulting.com/2012/10/setting-course-for-utc.html>

> Well, it turns out, one of them was a timezone-aware datetime, and all 
> the others were naive!  I finally figured it out when I tried

Welcome!

-- 
Adam Tauno Williams  GPG D95ED383
Systems Administrator, Python Developer, LPI / NCLA




More information about the Python-list mailing list