Proposal-temporal: Uncaught RangeError: largestUnit

Created on 14 Jul 2020  ·  2Comments  ·  Source: tc39/proposal-temporal

Possible wrong error message when :

temporalEndDate.difference(temporalStartDATE, { largestUnit: 'wrongValue' });

Throws:
image

But instead of listing possible values 'days', 'hours', 'minutes', and 'seconds' for the largestUnit it shows all from the Temporal.Duration properties.

documentation feedback

Most helpful comment

Found this 👍

// If you really need to calculate the difference between two Absolutes
// in years, you can eliminate the ambiguity by choosing your starting
// point explicitly. For example, using the corresponding UTC date:
utc = Temporal.TimeZone.from('UTC');
billion.toDateTime(utc).difference(epoch.toDateTime(utc), { largestUnit: 'years' });
  // => P31Y8M8DT1H46M40S

Don't want to be picky , but just reopened cause i think documentation should be more explicit about this particular possibility

All 2 comments

Found this 👍

// If you really need to calculate the difference between two Absolutes
// in years, you can eliminate the ambiguity by choosing your starting
// point explicitly. For example, using the corresponding UTC date:
utc = Temporal.TimeZone.from('UTC');
billion.toDateTime(utc).difference(epoch.toDateTime(utc), { largestUnit: 'years' });
  // => P31Y8M8DT1H46M40S

Don't want to be picky , but just reopened cause i think documentation should be more explicit about this particular possibility

Thanks for the report @romulocintra! I've tried to make it clearer in #774 — would you like to take a look and see if this wording would have helped?

Was this page helpful?
0 / 5 - 0 ratings