[Zope3-dev] Re: [Python-Dev] Holes in time

Shane Hathaway shane@zope.com
Fri, 03 Jan 2003 14:33:19 -0500


Guido van Rossum wrote:
>>Now, for current time zones, the C lib is a good source
>>of information, so I don't see why you wouldn't want to
>>use it.
> 
> 
> It seems you haven't been following this discussion.  The issue is not
> how to get information about timezones.  The issue is, given an API
> that implements an almost-but-not-quite-reversible function from local
> time to UTC, how to invert that function.

I have to admit I've also had trouble following the discussion also, 
until you described it that way.  Correct me if I'm wrong: you need the 
inverse of a mathematical function.

   utc_time = f(local_time)

I'll represent the inverse as "g":

   local_time = g(utc_time)

The graph of "f" looks like an upward slope, but it has little holes and 
overlaps at daylight savings boundaries.  The inverse is almost as 
strange, with periodic small jumps up and down.

You'd like to use the time zone information provided by the C library in 
the computation of "f", but the C library doesn't quite provide all the 
information you need to compute "g" correctly.  With those requirements, 
your only hope of computing "g" is to make some assumptions about "f".

That sounds perfectly reasonable, but may I suggest moving the 
assumption by changing the interface of the tzinfo class.  The 
utcoffset() method leads one to naively assume that functions f and g 
can both depend reliably on utcoffset().  Instead, tzinfo might have two 
methods, to_local(utc_date) and to_utc(local_date).  That way, the 
tzinfo object encapsulates the madness.

One downside is that then you can't expect normal programmers to write a 
correct tzinfo based on the C libraries.  They'll never get it right. 
:-)  It would have to be supplied with Python.

Shane