Skip to content

Parsing "%H%M%S" has either a bug or incorrect description #1697

@sharpMouse

Description

@sharpMouse

The documentation states that %S represents "Second number (00–60), zero-padded to 2 digits."

Given this, I would expect the following behavior when parsing timestamps with NaiveTime::parse_from_str:
✅ Valid: "010233" with "%H%M%S" parses successfully as 01:02:33.
❌ Too Long: "0102334" with "%H%M%S" fails with an error (correct).
❌ Too Short: "01023" with "%H%M%S" should fail — but instead, it parses as 01:02:03.

This seems inconsistent. Even more confusingly:
If we remove the first zero (e.g., "10233"), it parses as 10:23:03 — a completely different time.

Expected Behavior
For the format "%H%M%S", any input length other than 6 digits should result in an error.

Suggested Fix
Either:

Strict parsing: Enforce exact digit matching (6 digits for %H%M%S).

Document the behavior: Explicitly clarify that trailing digits may be ignored or that partial parsing is allowed.

Currently, the behavior is unintuitive and could lead to subtle bugs.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions