Skip to content

Reject impossible timestamps with one strict parser - #59

Merged
leoafarias merged 1 commit into
mainfrom
fix/strict-timestamp-parsing
Sep 11, 2026
Merged

leoafarias merged 1 commit into
mainfrom
fix/strict-timestamp-parsing

Conversation

@leoafarias

@leoafarias leoafarias commented Sep 11, 2026

Copy link
Copy Markdown
Member

Part of #57. It covers the impossible-value half. The missing-offset half changes what is valid, so it lands with the spec adoption in #56.

Problem. DateTime.tryParse rolls out-of-range fields over instead of rejecting them. 2026-02-30T10:00:00Z becomes 2 March, and 2026-09-11T25:61:61Z becomes the next day. The spec rules and the metadata accessors each parsed timestamps this way, so impossible generated.at and verified[].at values raised no advisory, and an impossible verification counted as usable.

Change.

  • parseIsoDateTime in lib/src/iso_date.dart accepts the ISO 8601 extended and basic forms, with optional fractional seconds and offset. It checks the month, the day (including leap years), the hour, minute and second, and the offset before it parses.
  • okf/invalid-generated and okf/invalid-verified use it, and so do OkfGeneration.atDateTime, OkfVerification.atDateTime/isUsable and the legacy timestamp accessor.
  • Timestamps with no offset are still accepted, which is unchanged.

Compatibility. Findings stay advisories, so no bundle that passes today fails. Bundles with impossible values now get the advisory they should always have had. A verification with an impossible at is no longer usable.

Checks. dart format, dart analyze --fatal-infos and dart test (219 tests) pass locally. New tests are in test/iso_date_test.dart.

There is no CHANGELOG entry: the first ## <version> section feeds release notes, so it will be added with the release.

DateTime.tryParse rolls out-of-range fields into another instant, so
2026-02-30T10:00:00Z validated and counted as a usable verification.
parseIsoDateTime checks each field before parsing, and both the spec
rules and the metadata accessors use it.
@leoafarias
leoafarias merged commit 5d41b78 into main Sep 11, 2026
4 checks passed
@leoafarias
leoafarias deleted the fix/strict-timestamp-parsing branch September 11, 2026 21:27
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.

1 participant