Skip to content

assert,util: compare Temporal objects by value - #67059

Open
pdeveltere wants to merge 3 commits into
nodejs:mainfrom
pdeveltere:assert-deep-temporal
Open

pdeveltere wants to merge 3 commits into
nodejs:mainfrom
pdeveltere:assert-deep-temporal

Conversation

@pdeveltere

@pdeveltere pdeveltere commented Oct 27, 2026 •

Copy link
Copy Markdown

assert.deepStrictEqual(), assert.deepEqual(), assert.partialDeepStrictEqual() and util.isDeepStrictEqual() consider any two Temporal objects of the same type equal, because Temporal objects keep their state in internal slots and have no own properties:

const a = Temporal.Instant.from('2026-01-01T00:00:00Z');
const b = Temporal.Instant.from('2036-01-01T00:00:00Z');

util.isDeepStrictEqual(a, b);    // true
assert.deepStrictEqual(a, b);    // passes
assert.notDeepStrictEqual(a, b); // throws

Date objects are compared by their time value for the same reason. This compares builtin Temporal objects with their equals method, and Temporal.Duration (which has no equals) field by field, so PT1H and PT60M are not equal. An object that only carries a Temporal.* tag is never equal to a builtin Temporal object.

The type checks come from internal/util/temporal, added in #63312, so this PR is stacked on it and its first commits are from that PR. Only assert,util: compare Temporal objects by value and its fixup belong to this PR. It stays a draft until #63312 lands; I'll rebase on main then.

Refs: #63312

@nodejs-github-bot

Copy link
Copy Markdown
Collaborator

Review requested:

  • @nodejs/startup

@nodejs-github-bot nodejs-github-bot added needs-ci PRs that need a full CI run. process Issues and PRs related to the process subsystem. util Issues and PRs related to the built-in util module. labels Oct 27, 2026
@github-actions

Copy link
Copy Markdown
Contributor

Welcome to Node.js, and thank you for your first contribution!

Before review, please take a moment to read:

Please make sure every commit is signed off. For a first pull request, GitHub Actions require collaborator approval and Jenkins CI must be started by a collaborator or triager, so an initial wait is normal.

Renegade334 and others added 3 commits October 27, 2026 14:40
Signed-off-by: Renegade334 <contact.9a5d6388@renegade334.me.uk>
Temporal objects keep their state in internal slots and have no own
properties, so deep equality considered any two Temporal objects of the
same type equal, e.g. two different Temporal.Instant values.

Compare builtin Temporal objects with their `equals` method, and
Temporal.Duration (which has no `equals`) field by field, the same way
Date objects are compared by their time value.

Signed-off-by: Pieter Develtere <pieterdeveltere@gmail.com>
@pdeveltere
pdeveltere force-pushed the assert-deep-temporal branch from 89b6910 to 7aa1149 Compare October 27, 2026 14:25
@pdeveltere
pdeveltere marked this pull request as ready for review October 27, 2026 20:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

needs-ci PRs that need a full CI run. process Issues and PRs related to the process subsystem. util Issues and PRs related to the built-in util module.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants