diff options
author | Alexander Belopolsky <alexander.belopolsky@gmail.com> | 2015-09-28 02:32:15 (GMT) |
---|---|---|
committer | Alexander Belopolsky <alexander.belopolsky@gmail.com> | 2015-09-28 02:32:15 (GMT) |
commit | 365ba8f6c1459cc5a902f3bec264ac07d8487c70 (patch) | |
tree | 21cfec1c779a69080a84785c37c4bc2f66480844 | |
parent | 36aff2db4ae7e113a8fce91b46301bd85e9c2f3b (diff) | |
download | cpython-365ba8f6c1459cc5a902f3bec264ac07d8487c70.zip cpython-365ba8f6c1459cc5a902f3bec264ac07d8487c70.tar.gz cpython-365ba8f6c1459cc5a902f3bec264ac07d8487c70.tar.bz2 |
Closes issue #23600: Wrong results from tzinfo.fromutc().
-rw-r--r-- | Lib/test/datetimetester.py | 23 | ||||
-rw-r--r-- | Misc/NEWS | 3 | ||||
-rw-r--r-- | Modules/_datetimemodule.c | 2 |
3 files changed, 27 insertions, 1 deletions
diff --git a/Lib/test/datetimetester.py b/Lib/test/datetimetester.py index 357fe13..63c3ae8 100644 --- a/Lib/test/datetimetester.py +++ b/Lib/test/datetimetester.py @@ -192,6 +192,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): @@ -24,6 +24,9 @@ Library - Issue #25203: Failed readline.set_completer_delims() no longer left the module in inconsistent state. +- Issue #23600: Default implementation of tzinfo.fromutc() was returning + wrong results in some cases. + - Issue #23329: Allow the ssl module to be built with older versions of LibreSSL. diff --git a/Modules/_datetimemodule.c b/Modules/_datetimemodule.c index 1d583a5..e3de537 100644 --- a/Modules/_datetimemodule.c +++ b/Modules/_datetimemodule.c @@ -3046,7 +3046,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); |