Skip to content

fix: compare Temporal durations without relative dates - #119

Merged
43081j merged 2 commits into
chaijs:mainfrom
mayankdhingra02:fix-temporal-duration-comparison
Nov 5, 2026
Merged

43081j merged 2 commits into
chaijs:mainfrom
mayankdhingra02:fix-temporal-duration-comparison

Conversation

@mayankdhingra02

Copy link
Copy Markdown
Contributor

Comparing two valid Temporal.Duration.from('P1M') values currently throws because total('nanoseconds') needs a reference date for years, months and weeks. Large day/time durations can also compare equal after a one-nanosecond difference is rounded away in the numeric total.

Compare years, months and weeks separately, then normalize the remaining day/time fields to exact seconds and subsecond components. This supplies no arbitrary calendar or date: one month stays distinct from 30 days, while the existing equivalence of one day and 24 hours is preserved. It uses instance methods and does not depend on a global Temporal or an instance's constructor property.

Added 14 regression/control cases and documented the duration equality rule. Follow-up to the Temporal support in #88 and #104.

Validation:

  • Full npm test on configured Node 25.9.0 and current Node 26.12.1: lint, 201 Node tests, 199 Chrome tests and 2 existing browser skips on each.
  • The final Temporal test file has 17 passes and 13 failures on unchanged main; all 30 pass with the fix.
  • 22,428 comparisons against an integer-nanosecond reference on Node 14/18/22/24/25/26 cover the polyfill, native Temporal and mixed native/polyfill/VM-realm values, including negative durations and precision boundaries.

The existing Istanbul command collects no ESM coverage, also reproduced on unchanged main. Node 12 imports the library successfully, but the locked Temporal polyfill itself fails to parse there; Temporal compatibility checks pass from Node 14 onward. Tests ran locally on macOS; Linux remains for CI.

mayankdhingra02 and others added 2 commits October 31, 2026 11:14
Compare years, months and weeks as calendar components, then normalize
remaining day/time fields exactly without choosing a reference date.
Preserve day/time equivalence and nanosecond differences lost by total().

Cover calendar durations, negative values, precision boundaries, nested
collections, constructor independence and input immutability. Document the
calendar-independent equality rule.

Signed-off-by: Mayank Dhingra <mayankdhingra02@gmail.com>
The agent went too far, this simplifies it.
@43081j
43081j force-pushed the fix-temporal-duration-comparison branch from d43dcee to aa9ae56 Compare November 5, 2026 11:39
@43081j
43081j merged commit c6791c2 into chaijs:main Nov 5, 2026
1 check 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.

2 participants