From 424a438b3791962e50590410972fdb0ebfd7b4a2 Mon Sep 17 00:00:00 2001 From: Ho <921345@emea.kuoni.int> Date: Fri, 8 Jun 2018 11:45:24 +0100 Subject: Fix isoparser misinterprets T24:00 - Update tests with the correct examples - Update AUTHORS.md - Closes GH issue #658 --- AUTHORS.md | 1 + dateutil/parser/isoparser.py | 8 +++++++- dateutil/test/test_isoparser.py | 10 +++++----- 3 files changed, 13 insertions(+), 6 deletions(-) diff --git a/AUTHORS.md b/AUTHORS.md index 1d7e41c..10b5e83 100644 --- a/AUTHORS.md +++ b/AUTHORS.md @@ -25,6 +25,7 @@ switch, and thus all their contributions are dual-licensed. - Brock Mendel (gh: @jbrockmendel) **R** - Brook Li (gh: @absreim) **D** - Carlos +- Cheuk Ting Ho (gh: @cheukting) **D** - Chris van den Berg (gh: bergvca) **D** - Christopher Cordero (gh: cs-cordero) **D** - Christopher Corley diff --git a/dateutil/parser/isoparser.py b/dateutil/parser/isoparser.py index e274837..3e2a09a 100644 --- a/dateutil/parser/isoparser.py +++ b/dateutil/parser/isoparser.py @@ -139,6 +139,10 @@ class isoparser(object): else: raise ValueError('String contains unknown ISO components') + if len(components) > 3 and components[3] == 24: + components[3] = 0 + return datetime(*components) + timedelta(days=1) + return datetime(*components) @_takes_ascii @@ -169,6 +173,9 @@ class isoparser(object): :return: Returns a :class:`datetime.time` object """ + components = self._parse_isotime(timestr) + if components[0] == 24: + components[0] = 0 return time(*self._parse_isotime(timestr)) @_takes_ascii @@ -368,7 +375,6 @@ class isoparser(object): # Standard supports 00:00 and 24:00 as representations of midnight if any(component != 0 for component in components[1:4]): raise ValueError('Hour may only be 24 at 24:00:00.000') - components[0] = 0 return components diff --git a/dateutil/test/test_isoparser.py b/dateutil/test/test_isoparser.py index 47ee500..41af44b 100644 --- a/dateutil/test/test_isoparser.py +++ b/dateutil/test/test_isoparser.py @@ -140,15 +140,15 @@ def test_full_tzoffsets(tzoffset): @pytest.mark.parametrize('dt_str', [ '2014-04-11T00', - '2014-04-11T24', + '2014-04-10T24', '2014-04-11T00:00', - '2014-04-11T24:00', + '2014-04-10T24:00', '2014-04-11T00:00:00', - '2014-04-11T24:00:00', + '2014-04-10T24:00:00', '2014-04-11T00:00:00.000', - '2014-04-11T24:00:00.000', + '2014-04-10T24:00:00.000', '2014-04-11T00:00:00.000000', - '2014-04-11T24:00:00.000000'] + '2014-04-10T24:00:00.000000'] ) def test_datetime_midnight(dt_str): assert isoparse(dt_str) == datetime(2014, 4, 11, 0, 0, 0, 0) -- cgit v1.2.3