Skip to content

Commit

Permalink
Merge pull request #751 from Cheukting/pylon_sprint
Browse files Browse the repository at this point in the history
Closes #658 Fix Isoparser misinterprets T24:00
  • Loading branch information
pganssle committed Jun 8, 2018
2 parents fa3faf3 + 3db2e32 commit 94cfe1e
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 6 deletions.
1 change: 1 addition & 0 deletions AUTHORS.md
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down
1 change: 1 addition & 0 deletions changelog.d/751.bugfix.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Changed handling of T24:00 to be compliant with the standard. T24:00 now represents midnight on the *following* day. Fixed by @cheukting (gh issue #658, gh pr #751)
8 changes: 7 additions & 1 deletion dateutil/parser/isoparser.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,10 @@ def isoparse(self, dt_str):
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
Expand Down Expand Up @@ -169,6 +173,9 @@ def parse_isotime(self, timestr):
: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
Expand Down Expand Up @@ -368,7 +375,6 @@ def _parse_isotime(self, timestr):
# 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

Expand Down
10 changes: 5 additions & 5 deletions dateutil/test/test_isoparser.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 94cfe1e

Please sign in to comment.