Parse two-digit UTC offset hours in Epoch::from_str

perfloop-oss/hifitime · Numeric Representation Loss

https://perfloop.ai/t/oss/case_xp65vk8hqz

Verdict

VERIFIED · settled 2026-11-10 · pull request opened as nyx-space/hifitime#540

What happened: The check fails before this change and passes with it.

Hypothesis

Gregorian/RFC3339 timestamp parsing may silently lose the tens digit of a numeric UTC offset's hour. That would change the returned instant and break formatter round trips for offsets of ten hours or more in magnitude. The submitter's results below remain unconfirmed in this run; affected-call prevalence is unknown.

The accepted revision is 91896f222c5712337e1ca3221ff3e067d20c768a. The documented library operation is Epoch::from_str (README.md:17–24), whose Gregorian branch calls Epoch::from_gregorian_str at src/epoch/mod.rs:1131–1140. The seed and edit target are Epoch::from_gregorian_str at src/epoch/gregorian.rs:550–653. At src/epoch/gregorian.rs:623–629, the parser sets prev_idx to idx + 1 and advances it again when the next token is OffsetHours. For an ASCII offset sign, this skips the first hour digit before the next numeric conversion at src/epoch/gregorian.rs:600–614. The parsed hours and minutes determine the signed adjustment at src/epoch/gregorian.rs:634–652.

The submitter reports that at HEAD 91896f2, Epoch::from_str("2024-06-01T12:00:00+10:00") returns Ok with 12:00:00 UTC rather than the expected 02:00:00 UTC. They report a 10-hour error with no error result. They report the same 600-minute error magnitude for +11:00, +12:00, +13:00, +10:30 and -10:00, while +05:00, +09:00, +05:30 and -08:00 are correct. They also report that the library's own Formatter::with_timezone output for +10:00 reparses 36,000,000,000,000 ns late. The Case must check these baseline observations rather than treat them as established measurements.

The reported reach is any RFC3339 timestamp with a zone offset at UTC+10 or more or UTC-10 or less, including offsets used in Sydney, Auckland and Honolulu. The submitter says upstream tests use only +05:00 and -05:00, where the dropped digit is zero. The checked formatter round trips at tests/epoch.rs:2009–2024 do exercise those two offsets. Formatter::with_timezone applies the supplied offset at src/efmt/formatter.rs:96–102.

The smallest useful check is a focused parse matrix against independently constructed UTC epochs, followed by formatting and reparsing the same instants. Explicit UTC constructors should supply the reference rather than the parser under investigation. Check each reported baseline error and each reported correct control. After repair, correct UTC instants and equality with the original Epoch after formatter reparsing are the deciding signals. A table-driven Rust test in tests/epoch.rs is a provisional layout choice, not an additional placement requirement; the requested round-trip coverage includes hour tens digits, both signs and half-hour minutes.

The submitter reports finding no upstream report among 505 issues and PRs. A fresh open-PR check before tracing found overlapping files, but the checked implementations remain distinct: https://github.com/nyx-space/hifitime/pull/512 generalizes precision and moves the nanosecond parser without removing this extra offset cursor advance; https://github.com/nyx-space/hifitime/pull/531 changes leap-second alignment, and https://github.com/nyx-space/hifitime/pull/535 changes time-scale reference-epoch conversions. None of those checked hunks repairs the offset-hour slice. Live issue searches were forbidden and local git history is shallow, so the submitter's 505-item search and historical upstream absence have not been independently confirmed.

Change to test: Read both offset-hour digits in Epoch::from_gregorian_str so Epoch::from_str applies the complete signed UTC offset. Add round-trip tests for offsets with a nonzero tens digit, both signs, and half-hour minutes, preserving the reported correct small-offset cases.

Where it lives

perfloop-oss/hifitime · src/epoch/mod.rs

Evidence

The check fails before this change and passes with it: `For the UTC-offset matrix at 2024-06-01T12:00:00 (hours 00-23, minutes 00-59, both signs, nanoseconds 0 and 123456789), Epoch::from_str returns the independently constructed UTC instant, and RFC3339/RFC3339_FLEX Formatter::with_timezone output reparses to the original Epoch.`

Checks: 6 of 6 passed. Verification: no defect found.

Timeline