]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
Issue#26616:Fixed a bug in datetime.astimezone() method.
authorAlexander Belopolsky <alexander.belopolsky@gmail.com>
Fri, 25 Mar 2016 19:42:59 +0000 (15:42 -0400)
committerAlexander Belopolsky <alexander.belopolsky@gmail.com>
Fri, 25 Mar 2016 19:42:59 +0000 (15:42 -0400)
Lib/test/datetimetester.py
Misc/NEWS
Modules/_datetimemodule.c

index 7743c67c8c33a2253d0a6f04d4bf947f858b0562..b9071640c4337d95ff34c7d13ebee87102e2a161 100644 (file)
@@ -3426,6 +3426,14 @@ class TestDateTimeTZ(TestDateTime, TZInfoBase, unittest.TestCase):
         self.assertEqual(dt, local)
         self.assertEqual(local.strftime("%z %Z"), "-0400 EDT")
 
+    @support.run_with_tz('EST+05EDT,M3.2.0,M11.1.0')
+    def test_astimezone_default_near_fold(self):
+        # Issue #26616.
+        u = datetime(2015, 11, 1, 5, tzinfo=timezone.utc)
+        t = u.astimezone()
+        s = t.astimezone()
+        self.assertEqual(t.tzinfo, s.tzinfo)
+
     def test_aware_subtract(self):
         cls = self.theclass
 
index 3baeeecae9dd2484de58eb5fd72229b3475389b8..1127e373032bed0412350ac81bf03b8c56fbf9c7 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -94,6 +94,8 @@ Core and Builtins
 Library
 -------
 
+- Issue #26616: Fixed a bug in datetime.astimezone() method.
+
 - Issue #21925: :func:`warnings.formatwarning` now catches exceptions on
   ``linecache.getline(...)`` to be able to log :exc:`ResourceWarning` emitted
   late during the Python shutdown process.
index e3de537a8d12bcb965ddf11ed648e203af253587..0e50023eead3e6f224e2e67061e1b5dfc424a170 100644 (file)
@@ -4749,7 +4749,12 @@ local_timezone(PyDateTime_DateTime *utc_time)
     PyObject *nameo = NULL;
     const char *zone = NULL;
 
-    delta = datetime_subtract((PyObject *)utc_time, PyDateTime_Epoch);
+    delta = new_delta(ymd_to_ord(GET_YEAR(utc_time), GET_MONTH(utc_time),
+                                 GET_DAY(utc_time)) - 719163,
+                      60 * (60 * DATE_GET_HOUR(utc_time) +
+                            DATE_GET_MINUTE(utc_time)) +
+                      DATE_GET_SECOND(utc_time),
+                      0, 0);
     if (delta == NULL)
         return NULL;
     one_second = new_delta(0, 1, 0, 0);