Skip to content

Add Temporal half-rounding boundary tests for PlainDate, PlainDateTime, PlainYearMonth, and ZonedDateTime#4996

Open
MidnightDesign wants to merge 3 commits intotc39:mainfrom
MidnightDesign:temporal-rounding-half-boundary
Open

Add Temporal half-rounding boundary tests for PlainDate, PlainDateTime, PlainYearMonth, and ZonedDateTime#4996
MidnightDesign wants to merge 3 commits intotc39:mainfrom
MidnightDesign:temporal-rounding-half-boundary

Conversation

@MidnightDesign
Copy link

@MidnightDesign MidnightDesign commented Mar 16, 2026

Note

This PR was drafted with the help of Claude Code. Apologies if that's not welcome here — happy to revise anything by hand.

Context

We're building temporal-php, a PHP 8.4 port of the TC39 Temporal API. We run the test262 suite as part of our CI (transpiled to PHP) and also use Infection for mutation testing. Infection systematically modifies source code and checks whether the test suite catches each mutation. Out of 11,983 mutations, several hundred escaped — and many of those escaped because the upstream test262 data doesn't exercise certain code paths. This PR adds tests to close the most impactful gaps we found.

Summary

Eight new test files across four Temporal types, all exercising the exact 0.5 fractional boundary in RoundRelativeDuration:

  • PlainDate, PlainDateTime, ZonedDateTime (since/ and until/): Test all 9 rounding modes at exact 0.5 fractional progress (183 days out of a 366-day leap year). The existing roundingmode-*.js tests use dates producing ~2.663 fractional years, where all half-* modes round identically. These new tests include both 1.5-year (odd integer) and 2.5-year (even integer) cases to distinguish halfEven from halfExpand.
  • PlainYearMonth (since/ and until/): Same boundary test, but uses June-starting dates because RoundRelativeDuration converts month remainders to days: Jun–Nov = 183 days in the 366-day year span from Jun 2019 to Jun 2020 (crossing Feb 29), giving exactly 183/366 = 0.5.

The until tests cover the positive direction; the since tests cover the negative direction (where halfExpand and halfCeil diverge).

How the gaps were found

Infection rewrites code like swapping halfExpand match arms, etc. If no test fails, the mutant "escapes." We traced ~80 escaped mutants back to the fact that all half-* rounding modes produce the same output with the current test data (no value near the 0.5 boundary), so entire match arms can be deleted or swapped without detection.

All expected values were verified against V8's Temporal implementation via test262-harness with esvu-installed V8 (d8).

…and dayOfWeek

The existing rounding mode tests for PlainDate.prototype.since() and
PlainDate.prototype.until() use dates that produce ~31.97 months of
difference, well above the 0.5 boundary. All half-* rounding modes
produce identical results, making it impossible to distinguish halfExpand
from halfTrunc, or halfEven from halfCeil.

These new tests use dates that produce exactly 0.5 fractional progress
(183/366 days in a leap year), causing all nine rounding modes to produce
distinct result patterns. The 2.5-year case specifically distinguishes
halfEven (rounds to nearest even integer 2) from halfExpand (rounds away
from zero to 3).

Also adds:
- inLeapYear century-year tests (1700, 1800, 1900, 2100, 2200) exercising
  the 100/400 rule that the basic test does not cover
- dayOfWeek tests across all 12 months of a year, since the basic test
  only checks 7 consecutive days within a single month

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@MidnightDesign MidnightDesign requested a review from a team as a code owner March 16, 2026 14:27
Remove unrelated dayOfWeek and inLeapYear tests. Add RoundRelativeDuration
spec references to info blocks. Extend half-boundary coverage to
PlainDateTime, PlainYearMonth, and ZonedDateTime (until + since).

PlainYearMonth uses June-starting dates because RoundRelativeDuration
converts month remainders to days: Jun-Nov = 183 days in a 366-day year
span (Jun 2019 - Jun 2020 crossing Feb 29), giving exactly 183/366 = 0.5.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@MidnightDesign MidnightDesign changed the title Add Temporal PlainDate tests for half-rounding boundary, century leap years, and dayOfWeek coverage Add Temporal half-rounding boundary tests for PlainDate, PlainDateTime, PlainYearMonth, and ZonedDateTime Mar 16, 2026
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