-
Notifications
You must be signed in to change notification settings - Fork 155
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
Comparison of LocalDateTime instances in different timezones (and maybe different calendars too) #912
Comments
I'm assuming that the two common use cases are going to be: "are these objects identical" ( If that assumption holds, then my preference is to keep I agree with the proposed behaviour for LocalDateTime.compare. |
I'm okay with the idea of |
Yep, I'd actually prefer something like |
Some other bikeshed ideas:
Another observation: another pattern for doing this comparison would be date1.difference(date2).equals(/* empty duration */) Is that too verbose? It might be fine. We could consider adding Temporal.Duration.prototype.isEmpty(), such that you can do date1.difference(date2).isEmpty() |
Meeting, Sept. 18: Due to lack of support, we will drop this. There is disagreement about whether equalsISO() and the other methods besides equals() present enough of a use case to justify their inclusion. equalsISO(), whether under that name or another name, can be considered for inclusion in a future proposal to extend Temporal. Aside from that, it seems like a good idea to add Duration.prototype.isZero (not "empty"). (→ #924) |
In #625 we recently decided to handle the "compare dates in different calendars" problem by creating two methods"
date.prototype.equals
for strict comparison anddate.prototype.equalsISO
for comparing just the ISO fields, ignoring calendars.In last week's meeting when we made this decision, I didn't think about how this would affect LocalDateTime where there's not only a calendar but also a time zone to compare. I apologize for cracking this topic open again.
I guess we could offer 4 equality methods on LocalDateTime:
equals
- all fields must matchequalsISO
- ignore calendarequalsUTC
?equalsAbsolute
? - ignore calendar and timezone???
- ignore timezone but not calendar. This one seems like a much less common use case, relative to the other three.Ugh. My first impression is that I'm not excited about 4 different comparison methods, even if we could figure out intuitive names for the last two.
Because one of LocalDateTime's design goals is to be a superset of the DateTime API, if we stick with the decision from #625 then we're committed to at least two of these:
equals
andequalsISO
.What's unclear is whether we should ignore the time zone in these two methods, add more methods, add options, etc.
FWIW, the current design of
LocalDateTime.compare
ignores timezone (because it uses Absolute.compare under the covers) and calendar. This is different from howDateTime.compare
works which is to return false if the calendars are different.My initial (not strongly held) opinion would be to do this:
equals
- all fields must match (to matchDateTime.compare
behavior)equalsISO
- ignore calendar, but timezone must matchequalsXxx
methods that ignore time zone. Users can always useTemporal.Absolute.compare(one.toAbsolute(), two.toAbsolute())
.compare
would do "object equality" as defined in Comparison and equality of dates with different calendars #625, where a zero is returned only if all fields match. It'd sort first bytoAbsolute().getEpochNanoseconds()
, next bycalendar.id
(to matchDateTime.compare
behavior), and finally byTimeZone.id
.Feedback appreciated.
The text was updated successfully, but these errors were encountered: