[Vobject] no TZ info in parsed dates?
Bill Janssen
janssen at parc.com
Tue Jun 9 20:34:05 CDT 2009
Jeffrey Harris <jeffrey at skyhouseconsulting.com> wrote:
> It would be great if you wanted to contribute your code for this back
> (with whatever olson->tzinfo library you want to use), I'm sure you're
> not the only one with this problem.
> > The mapping from Windows tz names to Olson tz names is available from
> > the Unicode Consortium at
> > http://unicode.org/cldr/data/diff/supplemental/windows_tzid.html.
Here's a start. Put this in a file, point it at that Unicode Consortium
XML file, and it will do the right thing for you. I believe this is
Python 2.3 safe.
Bill
-------------------------------------------------------------------------
def parseUnicodeConsortiumSupplementalDataXMLFile (filename):
"""Returns mapping of Windows timezone names onto Olson names"""
import xml.dom.minidom
mapping = {}
d = xml.dom.minidom.parse(filename)
if d:
windows_sections = [x for x in d.getElementsByTagName("mapTimezones") if (
x.hasAttribute("type") and (x.getAttribute("type") == u"windows"))]
for section in windows_sections:
# probably only one section
for node in section.getElementsByTagName("mapZone"):
if (node.hasAttribute("other") and node.hasAttribute("type")):
mapping[node.getAttribute("other")] = node.getAttribute("type")
return mapping
if __name__ == "__main__":
import pprint, sys
from dateutil import zoneinfo
for key, tzname in parseUnicodeConsortiumSupplementalDataXMLFile(sys.argv[1]).items():
tz = zoneinfo.gettz(tzname)
print '%32s %23s %s' % (key, tzname, tz)
More information about the VObject
mailing list