aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorClaudio Canepa <ccanepacc@gmail.com>2014-12-10 19:53:27 +0200
committerYaron de Leeuw <me@jarondl.net>2014-12-10 19:53:27 +0200
commitb8e944b5111350c79e2abfa77076d5a749f1de4d (patch)
tree7e0f39c9aa857c24302214c060cc20ba63c06c37
parentb2615c76fec3e6317a9967f791679d2b0a5e98aa (diff)
downloaddateutil-b8e944b5111350c79e2abfa77076d5a749f1de4d.tar.gz
windows: fix tzinfo for timezones without dst
fixes lp:1010050 and closes #2 This patch was taken almost as is from the launchpad merge request by @ccanepa : https://code.launchpad.net/~ccanepacc/dateutil/fix-isdst-in-tzwin/+merge/224424 Applyed to the git repo by @jarondl
-rwxr-xr-xdateutil/test/test.py12
-rw-r--r--dateutil/tzwin.py5
2 files changed, 17 insertions, 0 deletions
diff --git a/dateutil/test/test.py b/dateutil/test/test.py
index c00c3a8..af2e6d2 100755
--- a/dateutil/test/test.py
+++ b/dateutil/test/test.py
@@ -4,6 +4,8 @@ from __future__ import unicode_literals
import unittest
import calendar
import base64
+import sys
+
from datetime import *
@@ -16,6 +18,11 @@ from dateutil.rrule import *
from dateutil.tz import *
from dateutil import zoneinfo
+try:
+ from dateutil import tzwin
+except ImportError:
+ pass
+
class RelativeDeltaTest(unittest.TestCase):
now = datetime(2003, 9, 17, 20, 54, 47, 282310)
@@ -4003,5 +4010,10 @@ END:VTIMEZONE
self.assertEqual(dt.astimezone(tz=gettz("UTC-2")),
datetime(2007, 8, 6, 2, 10, tzinfo=tzstr("UTC-2")))
+ @unittest.skipUnless(sys.platform.startswith("win"), "requires Windows")
+ def testIsdstZoneWithNoDaylightSaving(self):
+ tz = tzwin.tzwin("UTC")
+ dt = parse("2013-03-06 19:08:15")
+ self.assertFalse(tz._isdst(dt))
# vim:ts=4:sw=4
diff --git a/dateutil/tzwin.py b/dateutil/tzwin.py
index 4276930..5e6864b 100644
--- a/dateutil/tzwin.py
+++ b/dateutil/tzwin.py
@@ -63,6 +63,9 @@ class tzwinbase(datetime.tzinfo):
return self._display
def _isdst(self, dt):
+ if not self._dstmonth:
+ # dstmonth == 0 signals the zone has no daylight saving time
+ return False
dston = picknthweekday(dt.year, self._dstmonth, self._dstdayofweek,
self._dsthour, self._dstminute,
self._dstweeknumber)
@@ -96,6 +99,8 @@ class tzwin(tzwinbase):
self._stdoffset = -tup[0]-tup[1] # Bias + StandardBias * -1
self._dstoffset = self._stdoffset-tup[2] # + DaylightBias * -1
+ # for the meaning see the win32 TIME_ZONE_INFORMATION structure docs
+ # http://msdn.microsoft.com/en-us/library/windows/desktop/ms725481(v=vs.85).aspx
(self._stdmonth,
self._stddayofweek, # Sunday = 0
self._stdweeknumber, # Last = 5