Skip to content

Commit

Permalink
Merge pull request #773 from pganssle/fix_isotime_2400
Browse files Browse the repository at this point in the history
Fix isotime behavior for strings with hour == 24
  • Loading branch information
pganssle committed Jun 20, 2018
2 parents ef6cddd + a41c4c6 commit 158be2b
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 1 deletion.
1 change: 1 addition & 0 deletions changelog.d/773.bugfix.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fixed an issue where ``isoparser.parse_isotime`` was unable to handle the ``24:00`` variant representation of midnight. (gh pr #773)
1 change: 1 addition & 0 deletions changelog.d/773.misc.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Added tests that parse_isotime only allows hours == 24 when the time is midnight. (gh pr #773)
2 changes: 1 addition & 1 deletion dateutil/parser/isoparser.py
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ def parse_isotime(self, timestr):
components = self._parse_isotime(timestr)
if components[0] == 24:
components[0] = 0
return time(*self._parse_isotime(timestr))
return time(*components)

@_takes_ascii
def parse_tzstr(self, tzstr, zero_as_utc=True):
Expand Down
20 changes: 20 additions & 0 deletions dateutil/test/test_isoparser.py
Original file line number Diff line number Diff line change
Expand Up @@ -452,6 +452,22 @@ def test_isotime(time_val, time_fmt, as_bytes):

assert iparser.parse_isotime(tstr) == time_val


@pytest.mark.parametrize('isostr', [
'24:00',
'2400',
'24:00:00',
'240000',
'24:00:00.000',
'24:00:00,000',
'24:00:00.000000',
'24:00:00,000000',
])
def test_isotime_midnight(isostr):
iparser = isoparser()
assert iparser.parse_isotime(isostr) == time(0, 0, 0, 0)


@pytest.mark.parametrize('isostr,exception', [
('3', ValueError), # ISO string too short
('14時30分15秒', ValueError), # Not ASCII
Expand All @@ -468,6 +484,10 @@ def test_isotime(time_val, time_fmt, as_bytes):
('14:59:59+25:00', ValueError), # Invalid tz hours
('14:59:59+12:62', ValueError), # Invalid tz minutes
('14:59:30_344583', ValueError), # Invalid microsecond separator
('24:01', ValueError), # 24 used for non-midnight time
('24:00:01', ValueError), # 24 used for non-midnight time
('24:00:00.001', ValueError), # 24 used for non-midnight time
('24:00:00.000001', ValueError), # 24 used for non-midnight time
])
def test_isotime_raises(isostr, exception):
iparser = isoparser()
Expand Down

0 comments on commit 158be2b

Please sign in to comment.