accessing tzinfo for timezones defined via tzwin which don't observe Daylight Saving Time throws ValueError because _dstmonth is 0

Bug #1010050 reported by Dick Swanson
20
This bug affects 4 people
Affects Status Importance Assigned to Milestone
dateutil
Confirmed
Medium
Tomi Hukkalainen

Bug Description

on windows:

from dateutil.tz import gettz
from datetime import datetime

tzinfo = gettz('UTC')
f = datetime.now(tzinfo)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\Python27\lib\site-packages\python_dateutil-1.5-py2.7.egg\dateutil\tzwin.py", line 32, in utcoffset
    if self._isdst(dt):
  File "C:\Python27\lib\site-packages\python_dateutil-1.5-py2.7.egg\dateutil\tzwin.py", line 67, in _isdst
    self._dstweeknumber)
  File "C:\Python27\lib\site-packages\python_dateutil-1.5-py2.7.egg\dateutil\tzwin.py", line 166, in picknthweekday
    first = datetime.datetime(year, month, 1, hour, minute)
ValueError: month must be in 1..12

Patch:
--- tzwin.py~ 2012-06-05 09:08:36.212393800 -0400
+++ tzwin.py 2012-06-07 10:24:33.878270600 -0400
@@ -62,6 +62,8 @@
         return self._display

     def _isdst(self, dt):
+ if self._dstmonth == 0:
+ return False
         dston = picknthweekday(dt.year, self._dstmonth, self._dstdayofweek,
                                self._dsthour, self._dstminute,
                                self._dstweeknumber)

Related branches

Changed in dateutil:
importance: Undecided → Medium
status: New → Confirmed
assignee: nobody → Tomi Pieviläinen (tpievila)
Revision history for this message
ccanepa (ccanepacc) wrote :

Update 2014

This defect is still present in python-dateutil 2.2 and in lp:dateutil 135

It will manifest when testing under py 3.X , will not show up in py 2.X due to another bug (will report as separate issue)

The rationale for the fix is solid: as seen in the docs of win32 API for TIME_ZONE_INFORMATION structure [1], dstmonth == 0 is a flag for 'this timezone don't have Daylight Saving Time'

We ( https://github.com/getnikola/nikola ) are affected for this defect.

I will post a merge request, with test, if that helps to land the patch.

[1] http://msdn.microsoft.com/en-us/library/windows/desktop/ms725481(v=vs.85).aspx

Revision history for this message
ccanepa (ccanepacc) wrote :
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.