changeset: 100752:361a92204d4a branch: 3.5 parent: 100747:ce7fdd69ba2c user: Alexander Belopolsky date: Fri Mar 25 15:42:59 2016 -0400 files: Lib/test/datetimetester.py Misc/NEWS Modules/_datetimemodule.c description: Issue#26616:Fixed a bug in datetime.astimezone() method. diff -r ce7fdd69ba2c -r 361a92204d4a Lib/test/datetimetester.py --- a/Lib/test/datetimetester.py Fri Mar 25 12:50:36 2016 +0100 +++ b/Lib/test/datetimetester.py Fri Mar 25 15:42:59 2016 -0400 @@ -3426,6 +3426,14 @@ 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 diff -r ce7fdd69ba2c -r 361a92204d4a Misc/NEWS --- a/Misc/NEWS Fri Mar 25 12:50:36 2016 +0100 +++ b/Misc/NEWS Fri Mar 25 15:42:59 2016 -0400 @@ -94,6 +94,8 @@ 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. diff -r ce7fdd69ba2c -r 361a92204d4a Modules/_datetimemodule.c --- a/Modules/_datetimemodule.c Fri Mar 25 12:50:36 2016 +0100 +++ b/Modules/_datetimemodule.c Fri Mar 25 15:42:59 2016 -0400 @@ -4749,7 +4749,12 @@ 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);