-
-
Notifications
You must be signed in to change notification settings - Fork 415
Open
Description
-
I am on the latest Pendulum version.
-
I have searched the issues of this repo and believe that this is not a duplicate.
-
OS version and name: Win10
-
Pendulum version: 3.1.0
Issue
pendulum.parse() trhows ParseError when parsing an ISO8601 formatted date with subsecond decimals with more than 9 digits, independent on whether time offset is present or not.
For instance, the following parse attempt work (truncating decimals to microsecond resolution)
>>> parse("2001-01-01T12:34:56.123456789")
DateTime(2001, 1, 1, 12, 34, 56, 123456, tzinfo=Timezone('UTC'))
>>> parse("2001-01-01T12:34:56.123456789Z")
DateTime(2001, 1, 1, 12, 34, 56, 123456, tzinfo=Timezone('UTC'))
>>> parse("2001-01-01T12:34:56.123456789+00:00")
DateTime(2001, 1, 1, 12, 34, 56, 123456, tzinfo=FixedTimezone(0, name="+00:00"))
>>> parse("2001-01-01T12:34:56.123456789+0000")
DateTime(2001, 1, 1, 12, 34, 56, 123456, tzinfo=FixedTimezone(0, name="+00:00"))but the same with an extra digit (even if it's 0) fail
parse("2001-01-01T12:34:56.1234567890")
Traceback (most recent call last):
File "<python-input-1>", line 1, in <module>
parse("2001-01-01T12:34:56.1234567890")
~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File ".venv\Lib\site-packages\pendulum\parser.py", line 36, in parse
return _parse(text, **options)
File ".venv\Lib\site-packages\pendulum\parser.py", line 51, in _parse
parsed = base_parse(text, **options)
File ".venv\Lib\site-packages\pendulum\parsing\__init__.py", line 78, in parse
return _normalize(_parse(text, **_options), **_options)
~~~~~~^^^^^^^^^^^^^^^^^^
File ".venv\Lib\site-packages\pendulum\parsing\__init__.py", line 125, in _parse
raise ParserError(f"Unable to parse string [{text}]")
pendulum.parsing.exceptions.ParserError: Unable to parse string [2001-01-01T12:34:56.1234567890]
```
It is expected that truncation (or even better rounding) to microseconds is applied independent of the number of digits present in the string.
The issue also happens when running in Linux (e.g., using the latest python3.14-slim container).Metadata
Metadata
Assignees
Labels
No labels