diff options
author | Ho <921345@emea.kuoni.int> | 2018-06-08 11:45:24 +0100 |
---|---|---|
committer | Paul Ganssle <paul@ganssle.io> | 2018-06-08 12:14:09 +0100 |
commit | 424a438b3791962e50590410972fdb0ebfd7b4a2 (patch) | |
tree | 6ef74a59a9b3a449b76c176f89e34d0a04eebfde | |
parent | 86e33512c41a04b989b14966a722608035a87b51 (diff) | |
download | dateutil-424a438b3791962e50590410972fdb0ebfd7b4a2.tar.gz |
Fix isoparser misinterprets T24:00
- Update tests with the correct examples
- Update AUTHORS.md
- Closes GH issue #658
-rw-r--r-- | AUTHORS.md | 1 | ||||
-rw-r--r-- | dateutil/parser/isoparser.py | 8 | ||||
-rw-r--r-- | dateutil/test/test_isoparser.py | 10 |
3 files changed, 13 insertions, 6 deletions
@@ -25,6 +25,7 @@ switch, and thus all their contributions are dual-licensed. - Brock Mendel <jbrockmendel@MASKED> (gh: @jbrockmendel) **R** - Brook Li (gh: @absreim) **D** - Carlos <carlosxl@MASKED> +- Cheuk Ting Ho <cheukting.ho@gmail.com> (gh: @cheukting) **D** - Chris van den Berg (gh: bergvca) **D** - Christopher Cordero <ccordero@pm.me> (gh: cs-cordero) **D** - Christopher Corley <cscorley@MASKED> 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) |