[Python-ideas] lack of time zone support
Bill Janssen
janssen at parc.com
Tue Jun 1 20:32:34 CEST 2010
To me, the single most irritating problem with the Python support for
date/time is the lack of support for time-zone understanding. This
breaks down into two major issues, %z and lack of a standard time-zone
table.
First, let's say I have to parse a Medusa log file, which contains time
stamps in the form "DD/Mon/YYYY:HH:MM:SS [+|-]HHMM", e.g.
"31/May/2010:07:10:04 -0800". What I'd like to write is
tm = time.mktime(time.strptime(timestamp, "%d/%b/%Y:%H:%M:%S %z"))
which is what I'd do if I was writing in C. But no! The Python
_strptime module doesn't support "%z". So instead, I have to pick the
timestamp apart and do things separately and remember that "-0800" isn't
octal, and also isn't the same as -800, and remember whether to add or
subtract it. This seems insane. So, IMO, support for %z should be
added to Lib/_strptime.py. We need a patch.
Secondly, we really need concrete subclasses of tzinfo, and some sort of
mapping. Lots of people have spent lots of time trying to figure out
this cryptic hint in datetime: "The datetime module does not supply any
concrete subclasses of tzinfo." I'm not sure whether pytz is the best
ideas, or what I use, the "zoneinfo" module from python-dateutil. With
that, I still have to add the Windows timezone names, using the table at
http://unicode.org/repos/cldr/trunk/common/supplemental/windowsZones.xml,
because the code in python-dateutil only works with Windows timezone
names when running on Windows.
Bill
More information about the Python-ideas
mailing list