[Zope3-dev] The Date Time and TimeZone question

Guido van Rossum guido@python.org
Sat, 16 Mar 2002 14:56:21 -0500


> If I put those all together, I don't understand what answer this gives to
> the original dilemma at:
> 
>     http://www.zope.org/Members/fdrake/DateTimeWiki/NaiveTime
> 
> That is, if I add "a day" to 12 noon on April 6, 2002, with a tzinfo
> object for our favorite time zone. the rules above seem clearly to
> say that the result is a datetime object for 12 noon on April 7,
> 2002, with the same tzinfo object attached.

Correct.

> But the tzinfo object has no way to know how that datetime was
> computed, and in particular can't know whether it was entered
> directly or was the result of adding "a day" to noon of the previous
> day.  How then could a chemical plant operator code a tzinfo object
> that "did the right thing" here, i.e. told them to shut down the
> 24-hour reaction at 1 pm on April 7, 2002?

Their application would have to compute the addition using UTC and
then convert to local time.  I haven't figured out the API for
conversions, but it could be something like this:

    t1 = datetimetz(<now>, tzinfo=LocalTime)
    t1u = t1.asUTC() # convert to UTC
    # t1 and t1u represent the same point in time
    t2u = t1u + timedelta(days=1)
    t2 = datetimetz(t2u, tzinfo=LocalTime)
    print "Shut down at", t2.ctime()

--Guido van Rossum (home page: http://www.python.org/~guido/)