[Vobject] no TZ info in parsed dates?

Bill Janssen janssen at parc.com
Tue Jun 9 21:03:16 CDT 2009


Here's an improved version.  By the way, why not just use dateutil to
create tzinfo objects, since you already require it?

Bill

def parseUnicodeConsortiumSupplementalDataXMLFile (filename):
    """Returns mapping of Windows timezone names onto Olson names.

    This uses the Unicode Consortium's supplemental data file, available
    at <http://unicode.org/cldr/data/common/supplemental/supplementalData.xml>.

    @param filename the file to read
    @type filename a string filename path
    @return a mapping of Windows timezone names to Olson timezone names
    @rtype dict(string->string)
    """
    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
    from vobject import icalendar
    for key, tzname in parseUnicodeConsortiumSupplementalDataXMLFile(sys.argv[1]).items():
        tz = zoneinfo.gettz(tzname)
        if tz:
            print '%32s  %23s  %s' % (key, tzname, tz)
            icalendar.registerTzid(key, tz)
                    
    


More information about the VObject mailing list