GeezerVisonThe World Wide Web, restored to 800 pixels of glory. |
| Home|About|Gaming cabinet|Archives|How it works|Starter sites |
GeezerVison is showing github.com — `parse` fails with subsecond decimals with more than 9 digits · Issue #935 · python-pendulum/pendulum Open Description
Issue
For instance, the following parse attempt work (truncating decimals to microsecond resolution): >>> pendulum.parse("2001-01-01T12:34:56.123456789Z") DateTime(2001, 1, 1, 12, 34, 56, 123456, tzinfo=Timezone('UTC')) but the same with an extra digit (even if it's 0) fail: >>> pendulum.parse("2001-01-01T12:34:56.1234567890Z") 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] Python's native datetime does not have issues with it: >>> datetime.datetime.fromisoformat("2001-01-01T12:34:56.1234567890Z") datetime.datetime(2001, 1, 1, 12, 34, 56, 123456, tzinfo=datetime.timezone.utc) It is expected that truncation (or even better rounding) to microseconds is applied independent of the number of digits present in the string. My current workaround is to extract the fractional part of the seconds, parse it as a float, and then add it to the DateTime instance (which accomplishes the rounding): >>> pendulum.parse("2001-01-01T12:34:56Z").add(seconds=float(".1234567890")) DateTime(2001, 1, 1, 12, 34, 56, 123457, tzinfo=Timezone('UTC')) The issue also happens when running in Linux (e.g., using the latest python3.14-slim container). ActivityMetadataMetadataAssigneesLabelsNo labels TypeProjectsMilestoneRelationshipsDevelopmentIssue actions |
| You are visitor 01402520 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |