Proposal-temporal: Date[Time].from(date.getFields()) forgets the calendar

Created on 2 Jun 2020  路  3Comments  路  Source: tc39/proposal-temporal

Small bug: Given the code

const d1 = Temporal.now.date().withCalendar("hebrew");
const d2 = Temporal.Date.from(d1.getFields());

d1 and d2 end up being different. d2 equals some date in Gregorian year 5780. Remedies:

  1. Ignore. This is an edge case / programmer error.
  2. Return the calendar in .getFields().
  3. Require the calendar in .from().

I have a slight preference for 2, regardless of whether we do 3.

calendar

Most helpful comment

This combined with what we discussed in #640 means that monthDay.with(monthDay.getFields()) will throw, but I believe that's a very minor concern, so I'm still going with option 2 in the polyfill.

All 3 comments

Option 2 seems best.

This combined with what we discussed in #640 means that monthDay.with(monthDay.getFields()) will throw, but I believe that's a very minor concern, so I'm still going with option 2 in the polyfill.

Option 2 is now the status quo, feel free to reopen this if anyone feels it needs further discussion or we need to mark it for later feedback review.

Was this page helpful?
0 / 5 - 0 ratings