-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
feat: initial support for Temporal equality #8007
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
✅ Deploy Preview for vitest-dev ready!Built without sensitive environment variables
To edit notification comments on pull requests, go to your Netlify project configuration. |
case '[object Temporal.PlainYearMonth]': | ||
case '[object Temporal.PlainMonthDay]': | ||
case '[object Temporal.Duration]': | ||
return a.toString() === b.toString() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you know which is preferred whether toString
equality and builtin equals
method? https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Temporal/ZonedDateTime/equals
It looks like there are several old issues mentions calendar comparison (such as tc39/proposal-temporal#625), but the discussion seem quite technical 😅
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
.equals()
seems to compare including the calendar, so I think it's a good suggestion. Let's do it!
For Temporal.Duration
this .equals()
method doesn't exist, but I wasn't sure about that one to begin with. For Durations, there IS actually ambiguity. For example, are 60 seconds and 1 minute the same? If you compare the duration in time, yes; but if you literally compare all their components, no. Also, for example "1 day" is not necessarily the same as "24 hour" and depends on context.
My suggestion is to use .toString()
for durations so it does a literal comparison of all the different components.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Indeed it looks like Duration is tricky. tc39/proposal-temporal#856 seems to explain the details.
As a builtin equality, I think choosing toString
comparison makes sense since that's the most strict way to do it. Users can still add own custom equality tester to loosen it if desired.
@hi-ogawa I updated the PR:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks!
Description
Fixes #7991
Please don't delete this checklist! Before submitting the PR, please make sure you do the following:
pnpm-lock.yaml
unless you introduce a new test example.Tests
pnpm test:ci
.Documentation
pnpm run docs
command.Changesets
feat:
,fix:
,perf:
,docs:
, orchore:
.