Skip to content

Fix dateparse for optional seconds and tab whitespace - #155

Merged
staktrace merged 3 commits into
staktrace:masterfrom
staktrace-bot:fix-dateparse-optional-seconds-and-fws
Nov 21, 2026
Merged

staktrace merged 3 commits into
staktrace:masterfrom
staktrace-bot:fix-dateparse-optional-seconds-and-fws

Conversation

@staktrace-bot

Copy link
Copy Markdown
Collaborator

dateparse had two RFC 5322 Date parsing bugs from #154.

  • Seconds are optional (hour ":" minute [":" second]). The Second state always parsed the next token as u8 seconds, so +0100 was read as 100 seconds and zones like -0500 or GMT failed. A token is now treated as seconds only if it is one or two ASCII digits; otherwise it is handled as the timezone.
  • Folding whitespace (FWS) can include tabs and CRLF, but the tokenizer only split on spaces and colons. It now also splits on tab, CR, and LF.

Fixes #154

Comment thread src/dateparse.rs Resolved
Move the Timezone arm into a shared helper with no behavior change.
@staktrace-bot
staktrace-bot force-pushed the fix-dateparse-optional-seconds-and-fws branch from 2aec4b5 to d5b701e Compare November 21, 2026 18:49
Grok Bot added 2 commits November 21, 2026 14:03
RFC 5322 section 3.3 makes seconds optional in the time production
(hour ":" minute [":" second]). The Second state previously always
parsed the next token as u8 seconds, so a numeric zone like +0100 was
read as 100 seconds and zones like -0500 or GMT failed.

Only treat a token of one or two ASCII digits as seconds; otherwise
handle the token as a timezone. Add tests for the issue staktrace#154 cases.
RFC 5322 folding whitespace (FWS) in Date fields can include tabs
and CRLF, but dateparse only split on spaces and colons, so dates
with tabs failed to parse (issue staktrace#154).

Also split on tab, CR, and LF, and test a tab-separated date against
its space-separated equivalent.
@staktrace-bot
staktrace-bot force-pushed the fix-dateparse-optional-seconds-and-fws branch from d5b701e to 6d8df38 Compare November 21, 2026 19:04
@staktrace
staktrace merged commit 0454f73 into staktrace:master Nov 21, 2026
5 checks passed
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.

dateparse: date without seconds reads the zone as seconds (wrong timestamp or error)

2 participants