Skip to content

Read ISO 8601 calendar units with a count of zero - #6

Merged
pscheid92 merged 3 commits into
mainfrom
iso8601-zero-calendar-units
Nov 9, 2026
Merged

pscheid92 merged 3 commits into
mainfrom
iso8601-zero-calendar-units

Conversation

@pscheid92

Copy link
Copy Markdown
Owner

Finding 1 of the full review, and the only change of behavior in this round.

ISO8601 rejected every year, month, week and day because a calendar unit has no fixed length. With a count of zero
that reason does not hold: zero days are no time at all, however long a day is. And real producers write such
durations:

Producer Writes Before Now
moment.js, zero duration "P0D" ErrCalendarUnits 0s
Python isodate, zero duration "P0D" ErrCalendarUnits 0s
date-fns, every duration "P0Y0M0DT1H30M0S" ErrCalendarUnits, even with AcceptDays 1h30m0s

The rule: a year, month, week or day whose count is zero and has no fraction adds nothing and is no error, in every
mode (With, the wrapper types, Format.Parse). Everything else is as before: "P0Y1D" and "P1Y0D" are calendar
units, "P0.0D" is ErrCalendarUnits without AcceptDays and a syntax error with it, "P0DT" is a syntax error.

  • The reference parser has the same rule, and 20 seconds of FuzzParseMatchesReference found no disagreement.
  • The compat tests list the new difference from the format tag option, which rejects these durations, and
    FuzzUnmarshalMatchesFormatTag ran for 30 seconds without a finding.
  • Coverage stays at 100%.

After the CI and tooling PR merges, this branch needs main merged in: both touch
internal/compat/compat_test.go.

ISO8601 rejected every year, month, week and day, whatever its count,
because a calendar unit has no fixed length. A count of zero has one:
zero days are no time at all, however long a day is.

Real producers write such durations. moment.js and Python's isodate
write a zero duration as "P0D", and date-fns writes every component of
every duration, as in "P0Y0M0DT1H30M0S". Both were rejected, with and,
for years and months, even without AcceptDays.

A calendar unit whose count is zero and has no fraction is now read in
every mode, by With, the wrapper types and Format.Parse alike. A count
with a fraction, as in "P0.0D", stays an error, as it is with
AcceptDays. The reference parser follows the same rule, and the compat
tests list the new difference from the format tag option, which
rejects these durations.
@pscheid92
pscheid92 merged commit 7a7e843 into main Nov 9, 2026
19 checks passed
@pscheid92
pscheid92 deleted the iso8601-zero-calendar-units branch November 9, 2026 20:47
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