[Datetime-SIG] IANA TZ database statistics

Tim Peters tim.peters at gmail.com
Thu Sep 24 02:47:28 CEST 2015

> I added a method to datetimetester [1] to compute some overall statistics on
> tzfiles.  My code ignores "version 2" data, so I include only transitions
> that fall within 32-bit time_t (1900 to 2038 range).

>From staring at zic.c, looks like (so far) the data in the version 2
section is identical to that in the version 1 section, except written
out in wider data formats.  The pretty clear intent is that they never
intend to generate explicit transitions beyond 2037 in any version,
until it's after 2037 in the real world and they need to do so because
a POSIX TZ rule can't handle some new goofy exception (and version 2
also contains a POSIX TZ rule at the end, when possible).  Then
they'll need to add new transitions in the version 2 section only
(version 1 data formats are too narrow to record them).

> I am considering making the cut-off at 1970 and assume 1970 standard
> time for all times before that year.

Is there a real need for a "high performance" tzinfo?  That is, who
cares? ;-)  It would sure be _surprising_ if a Python wrapping of
zoneinfo returned different results than native Linux tools wrapping
the same thing.

>  I think this is best we can do on Windows

Of course not, if by "best" we mean "gets the same answers everyone
else gets".  In that case, "best" is returning what the IANA database
says should be returned in all cases.

> where (IIRC) mktime does not work for times before epoch.  (What about
> localtime?)

Python 3.4.3 (v3.4.3:9b73f1c3e601, Feb 24 2015, 22:44:40) [MSC v.1600
64 bit (AMD64)] on win32
>>> import time
>>> time.localtime(0)
time.struct_time(tm_year=1969, tm_mon=12, tm_mday=31, tm_hour=18,
tm_min=0, tm_sec=0, tm_wday=2, tm_yday=365, tm_isdst=0)

>>> time.localtime(-1)
Traceback (most recent call last):
  File "<pyshell#2>", line 1, in <module>
OSError: [Errno 22] Invalid argument

Which is another meaning for "best":  avoid flaky C library functions

>>> epoch = datetime(1970, 1, 1)
>>> epoch + timedelta(seconds=1e11)
datetime.datetime(5138, 11, 16, 9, 46, 40)
>>> import time
>>> time.localtime(1e11)
Traceback (most recent call last):
  File "<pyshell#13>", line 1, in <module>
OSError: [Errno 22] Invalid argument

More information about the Datetime-SIG mailing list