Skip to content

parser: accept a 9-digit HHMMSSmmm time token (#1442) - #1603

Open
DawnofGenX wants to merge 2 commits into
dateutil:masterfrom
DawnofGenX:fix-hhmmss-microseconds-1442
Open

DawnofGenX wants to merge 2 commits into
dateutil:masterfrom
DawnofGenX:fix-hhmmss-microseconds-1442

Conversation

@DawnofGenX

Copy link
Copy Markdown

Problem

parser.parse() rejects a bare 9-digit time token (hour-minute-second plus
milliseconds, no decimal point):

>>> from dateutil import parser
>>> parser.parse("20010203 040506789")
ParserError: Unknown string format: 20010203 040506789

strptime handles the same string with %Y%m%d %H%M%S%f. A 9-digit token
matches no branch in _parse_numeric_token, so it falls through to the year
path and fails.

Changes

Add an HHMMSSmmm branch for a 9-digit token when a date has already been seen
and the hour is not yet set.

Verification

  • New test ParserTest::testHHMMSSMilliseconds fails on main (ParserError)
    and passes with the fix, for both "20010203 040506789" and
    "20010203T040506789".
  • tests/test_parser.py: 232 passed, 14 xfailed.
  • Full suite (excluding tests/property, which needs a data file absent here):
    only pre-existing tests/test_tz.py failures remain, which reproduce
    identically on main.

`parser.parse("20010203 040506789")` raised `ParserError` because a
9-digit numeric token matched no branch in `_parse_numeric_token` and fell
through to the year path. Treat it as `HHMMSSmmm` when a date has already
been seen and the hour is still unset.
@DawnofGenX
DawnofGenX force-pushed the fix-hhmmss-microseconds-1442 branch from 5a529a6 to 6cce9be Compare October 7, 2026 13:36

@Wkhanex Wkhanex left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nine-digit time tokens agree with direct datetime construction at midnight, ordinary times and 23:59:59, with millisecond values 000, 001, 009, 100 and 999. Invalid hour/minute/second fields still raise ParserError.

Checked 6cce9be50917 with standalone Python 3.12.14 checks (18 passing assertions). I haven't run the full upstream suite.

…econds-1442

# Conflicts:
#	tests/test_internals.py
@DawnofGenX

Copy link
Copy Markdown
Author

Merged current master into the branch to clear the conflict (the only conflict was an import-order clash in tests/test_internals.py — kept both import sys and import pytest).

Re-verified on the merged tree: tests/test_parser.py + tests/test_internals.py → 235 passed, 14 xfailed; full suite → 5029 passed, 266 skipped, 17 xfailed, 3 failed — and those same three tz-data tests (test_gettz_link, test_gettz_local_abbreviation_without_time_zone_data, test_dst_matches_tzdata_zi) fail identically on a pristine master worktree here, so they are environmental, not from this branch.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants