Learn how easy it is to sync an existing GitHub or Google Code repo to a SourceForge project! See Demo


#589 win32timezone errors in dst/pst

Brian Matthews

getWinInfo in timeZoneInfo class is return incorrect dynamic info
return self.dynamicInfo.get(targetYear, self.dynamicInfo[RangeItemLast()])

self.dynamicInfo is a dictionary, not a List

it should be something like:
keys = self.dynamicInfo.keys().sort()
return self.dynamicInfo.get(targetYear, self.dynamicInfo[keys[RangeItemLast()]])


    • status: open --> closed-invalid
  • self.dynamicInfo is a dictionary, but it is also a RangeMap. A RangeMap accepts RangeItemLast() as a parameter to .__getitem__ to retrieve the last item (see the docstring for RangeMap). Therefore, it should not be necessary to sort any keys manually.

    Additionally, the suggestion to use
    keys = self.dynamicInfo.keys().sort()

    would not work because .sort() does not return a value and because RangeItemLast() is not an integer, but a special value indicating the last item in a RangeMap.

    I'm going to mark this ticket as invalid, because it does not provide any actionable symptoms. Can you provide an example of what you are calling, what you expect, and what happens instead? For me, all of the relevant tests still pass, but that doesn't mean that you haven't found a use case that doesn't work. Please describe it and I'll be more than happy to find a fix.


  • Brian Matthews
    Brian Matthews

    Ok, my apologies I did not look deep enough.
    The problem is the utcoffset for years 2008-2012 are wrong. 2007 is OK
    For 2012 it thinks the dst switch is April-1, but it should be March 11

    >>> from win32timezone import TimeZoneInfo
    >>> from datetime import datetime
    >>> tzi = TimeZoneInfo('Pacific Standard Time')
    >>> dt = datetime(2012,4,1)
    >>> print tzi.utcoffset(dt)
    -1 day, 16:00:00
    >>> dt = datetime(2012,4,1,4)
    >>> print tzi.utcoffset(dt)
    -1 day, 17:00:00

  • Thanks for the update. I'll get it resolved promptly.

    • status: closed-invalid --> open-accepted
  • Brian Matthews
    Brian Matthews

    The reason this occurs is getWinInfo returns the dynamic entry for 2006, and it should return the entry for 2007

    • status: open-accepted --> closed-fixed
  • Fixed in aa3a7ed32634. It should be safe to copy win32timezone.py into an existing installation as a hotfix.

  • Brian Matthews
    Brian Matthews

    thanks for the quick response...