FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Accept ISO 8601 fractional seconds with more than 9 digits by vineethsaivs · Pull Request #976 · python-pendulum/pendulum · GitHub

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

Filter by extension

Filter by extension .py  (2) All 1 file type selected
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
2 changes: 1 addition & 1 deletion src/pendulum/parsing/iso8601.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
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
" )?"
# Timezone offset
" (?P<tz>"
Expand Down
24 changes: 24 additions & 0 deletions tests/parsing/test_parse_iso8601.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import pytest

from pendulum.parsing import parse_iso8601
from pendulum.parsing.iso8601 import parse_iso8601 as parse_iso8601_python


try:
Expand Down Expand Up @@ -214,3 +215,26 @@ def test_parse_iso8601_duration_invalid():
# Must include at least one element
with pytest.raises(ValueError):
parse_iso8601("P")


@pytest.mark.parametrize(
["text", "expected"],
[
# 10 and more fractional-second digits (issue #935)
(
"2001-01-01T12:34:56.1234567890",
datetime(2001, 1, 1, 12, 34, 56, 123456),
),
(
"2001-01-01T12:34:56.123456789012",
datetime(2001, 1, 1, 12, 34, 56, 123456),
),
("12:34:56.1234567890", time(12, 34, 56, 123456)),
],
)
def test_parse_iso8601_subsecond_more_than_nine_digits(text, expected):
# The pure-Python ISO 8601 parser must accept fractional seconds with more
# than 9 digits and truncate to microsecond resolution, matching the Rust
# parser and datetime.fromisoformat, instead of failing to parse.
# https://github.com/python-pendulum/pendulum/issues/935
assert parse_iso8601_python(text) == expected

Back | FazBrowse Home | New Git URL