Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/pendulum/parsing/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
# Subsecond part (optional)
" (?P<subsecondsection>"
" (?:[.|,])" # Subsecond separator (optional)
r" (?P<subsecond>\d{1,9})" # Subsecond
r" (?P<subsecond>\d+)" # Subsecond (truncated to microseconds later)
" )?"
")?"
"$",
Expand Down
2 changes: 1 addition & 1 deletion src/pendulum/parsing/iso8601.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
# Subsecond part (optional)
" (?P<subsecondsection>"
" (?:[.,])" # Subsecond separator (optional)
r" (?P<subsecond>\d{1,9})" # Subsecond
r" (?P<subsecond>\d+)" # Subsecond (truncated to microseconds later)
" )?"
# Timezone offset
" (?P<tz>"
Expand Down
4 changes: 4 additions & 0 deletions tests/parsing/test_parse_iso8601.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,10 @@
"2016-10-06T12:34:56.123456789+05:30",
datetime(2016, 10, 6, 12, 34, 56, 123456, FixedTimezone(+19800)),
),
# More fractional digits than microsecond precision (truncated)
("2016-10-06T12:34:56.123456789012", datetime(2016, 10, 6, 12, 34, 56, 123456)),
("12:34:56.123456789012", time(12, 34, 56, 123456)),
("20161006T123456,123456789012", datetime(2016, 10, 6, 12, 34, 56, 123456)),
# Week date with time
("2008-W39-6T09", datetime(2008, 9, 27, 9, 0, 0, 0)),
],
Expand Down
16 changes: 16 additions & 0 deletions tests/parsing/test_parsing.py
Original file line number Diff line number Diff line change
Expand Up @@ -700,3 +700,19 @@ def test_exif_edge_case():
assert parsed.hour == 15
assert parsed.minute == 45
assert parsed.second == 28


def test_subsecond_more_than_nine_digits():
# Fractional seconds beyond microsecond precision are truncated (issue #935)
text = "2016-10-06T12:34:56.123456789012"

parsed = parse(text)

assert parsed.microsecond == 123456

# The common parser handles the same input
text = "2016/10/06 12:34:56.123456789012"

parsed = parse(text)

assert parsed.microsecond == 123456