Skip to content

Commit

Permalink
Merge pull request #721 from pganssle/comma_sep
Browse files Browse the repository at this point in the history
Comma separator for ISO 8601 parser
  • Loading branch information
pganssle committed May 16, 2018
2 parents ad98073 + 86c8f5b commit 4ec670d
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 4 deletions.
1 change: 1 addition & 0 deletions changelog.d/721.bugfix.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Add support for ISO 8601 times with comma as the decimal separator. (gh pr #721)
8 changes: 5 additions & 3 deletions dateutil/parser/isoparser.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,9 @@ def isoparse(self, dt_str):
- ``hh:mm:ss.sss`` or ``hh:mm:ss.ssssss`` (3-6 sub-second digits)
Midnight is a special case for `hh`, as the standard supports both
00:00 and 24:00 as a representation.
00:00 and 24:00 as a representation. The decimal separator can be
either a dot or a comma.
.. caution::
Expand Down Expand Up @@ -193,7 +195,7 @@ def parse_tzstr(self, tzstr, zero_as_utc=True):
_MICROSECOND_END_REGEX = re.compile(b'[-+Z]+')
_DATE_SEP = b'-'
_TIME_SEP = b':'
_MICRO_SEP = b'.'
_MICRO_SEPS = b'.,'

def _parse_isodate(self, dt_str):
try:
Expand Down Expand Up @@ -349,7 +351,7 @@ def _parse_isotime(self, timestr):

if comp == 3:
# Microsecond
if timestr[pos:pos + 1] != self._MICRO_SEP:
if timestr[pos:pos + 1] not in self._MICRO_SEPS:
continue

pos += 1
Expand Down
3 changes: 2 additions & 1 deletion dateutil/test/test_isoparser.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,8 @@ def test_ymd_hms(dt, date_fmt, time_fmt, tzoffset):
DATETIMES = [datetime(2017, 11, 27, 6, 14, 30, 123456)]
@pytest.mark.parametrize('dt', tuple(DATETIMES))
@pytest.mark.parametrize('date_fmt', YMD_FMTS)
@pytest.mark.parametrize('time_fmt', (x + '.%f' for x in HMS_FMTS))
@pytest.mark.parametrize('time_fmt', (x + sep + '%f' for x in HMS_FMTS
for sep in '.,'))
@pytest.mark.parametrize('tzoffset', TZOFFSETS)
@pytest.mark.parametrize('precision', list(range(3, 7)))
def test_ymd_hms_micro(dt, date_fmt, time_fmt, tzoffset, precision):
Expand Down

0 comments on commit 4ec670d

Please sign in to comment.