-
Notifications
You must be signed in to change notification settings - Fork 158
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
Calendar-ignoring compare
behaves unexpectedly for non-ISO calendar PlainYearMonth comparisons
#1846
Comments
Another option ("option 4") would be to remove PlainYearMonth.compare (see js-temporal/proposal-temporal-v2#18 for why it doesn't exist on PlainMonthDay). Currently the status quo (option 1) is my preference. This corresponds to the semantics of "comparing the day on which the month starts". Option 4 would correspond to the semantics of "comparing the month as a whole" which is impossible because months that start on the same day can be different lengths, as you pointed out. I think option 2 is probably a non-starter since we got strong feedback that the lexicographical comparison was not good in |
Good idea re: "remove" option. I added it to the list in the OP. I don't have a strong opinion about which option is best. Let's discuss at next champions meeting? While thinking about this problem, I added js-temporal/proposal-temporal-v2#21 to add additional "strict" (all fields must match) methods in V2. |
Although we were a bit short-handed at the champions meeting today, we discussed this. Shane, Richard, and I all prefer option 1, the status quo. If any champions have a strong preference otherwise, holler soon, and otherwise I'll close this issue. |
Sounds good to me. Here's an excerpt from meeting notes to explain the decision:
Let's leave this issue open as a reminder to update the docs to explain this behavior. Doc text can be something like below. When comparing Temporal.PlainYearMonth.compare(
{ year: 2003, month: 1, calendar: 'chinese' }, // first Chinese month of 2003
{ year: 2003, month: 2, calendar: 'gregory' } // second Gregorian moth of 2003
)
// => 0 (because these months start on the same ISO 8601 date: 2003-02-01 |
At the request of one of the TC39 committee members, we made a change right before Stage 3 to ignore Calendar and TimeZone in
compare
methods.The previous behavior was to lexicographically compare calendar and timezone IDs. The new (and current) behavior is to ignore timezone and calendar, so that only ISO fields (and, for ZDT, the instant) is compared.
While working on the docs for this change (#1845) I noticed that this change has very odd results when comparing PlainYearMonth instances across calendars, because comparison currently only compares the ISO dates of the first day of the month. Sometimes, a non-ISO month happens to fall on the first day of an ISO month, which can yield the weird circumstance of two obviously-different months being considered equal by Temporal.
Is this OK? Unlike all other types with a
compare
method, PlainYearMonth doesn't have a calendar-independent way to decide if two instances are "equal", because months are inherently calendar-specific.Seems like our choices include:
compare
method from this type. (EDIT: added this per @ptomato suggestion below)Are there any other options?
The text was updated successfully, but these errors were encountered: