]> granicus.if.org Git - python/commitdiff
Closes issue #23600: Wrong results from tzinfo.fromutc().
authorAlexander Belopolsky <alexander.belopolsky@gmail.com>
Mon, 28 Sep 2015 02:31:45 +0000 (22:31 -0400)
committerAlexander Belopolsky <alexander.belopolsky@gmail.com>
Mon, 28 Sep 2015 02:31:45 +0000 (22:31 -0400)
Lib/test/datetimetester.py
Misc/NEWS
Modules/_datetimemodule.c

index a942d4de81b8314e4b9583b6cca01735561ca1c4..3d50fc15d8b1378ef12735e32f37c3d16599bb14 100644 (file)
@@ -180,6 +180,29 @@ class TestTZInfo(unittest.TestCase):
                 self.assertEqual(derived.utcoffset(None), offset)
                 self.assertEqual(derived.tzname(None), oname)
 
+    def test_issue23600(self):
+        DSTDIFF = DSTOFFSET = timedelta(hours=1)
+
+        class UKSummerTime(tzinfo):
+            """Simple time zone which pretends to always be in summer time, since
+                that's what shows the failure.
+            """
+
+            def utcoffset(self, dt):
+                return DSTOFFSET
+
+            def dst(self, dt):
+                return DSTDIFF
+
+            def tzname(self, dt):
+                return 'UKSummerTime'
+
+        tz = UKSummerTime()
+        u = datetime(2014, 4, 26, 12, 1, tzinfo=tz)
+        t = tz.fromutc(u)
+        self.assertEqual(t - t.utcoffset(), u)
+
+
 class TestTimeZone(unittest.TestCase):
 
     def setUp(self):
index 6793215a310faa4b653d0cea8c296c322b93413d..63730faa2ef719ef54b5d5fd13f20084a4bc48c2 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -81,6 +81,9 @@ Core and Builtins
 Library
 -------
 
+- Issue #23600: Default implementation of tzinfo.fromutc() was returning
+  wrong results in some cases.
+
 - Issue #25203: Failed readline.set_completer_delims() no longer left the
   module in inconsistent state.
 
index cabe4edb6a4ef88a0edb944771a87dd529e10b72..6084ffa2013dd6bd19cc08053af786155b462b34 100644 (file)
@@ -3040,7 +3040,7 @@ tzinfo_fromutc(PyDateTime_TZInfo *self, PyObject *dt)
         goto Fail;
     if (dst == Py_None)
         goto Inconsistent;
-    if (delta_bool(delta) != 0) {
+    if (delta_bool((PyDateTime_Delta *)dst) != 0) {
         PyObject *temp = result;
         result = add_datetime_timedelta((PyDateTime_DateTime *)result,
                                         (PyDateTime_Delta *)dst, 1);