-
Notifications
You must be signed in to change notification settings - Fork 172
Description
I observed this bug with the reference polyfill:
const d = new Temporal.Duration(1, 0, 0, 0, 1);
const relativeTo = new Temporal.PlainDate(2020, 2, 29);
console.log(d.round({ smallestUnit: 'years', relativeTo }).toString());
console.log(d.total({ unit: 'years', relativeTo }));This fails the following assertion:
proposal-temporal/polyfill/lib/ecmascript.mjs
Line 3261 in 857d12d
| if (sign === 1) assert(startEpochNs.leq(destEpochNs) && destEpochNs.leq(endEpochNs), `${unit} was 0 days long`); |
It occurs because destEpochNs (2021-02-28T01:00Z) > endEpochNs (2021-02-28T00:00Z). If I understand the problem correctly, startEpochNs ought to have the latter value and endEpochNs ought to be 2022-02-28T00:00Z, probably because r1 and r2 should be 1 and 2 instead of 0 and 1.
I'm hopeful that this is a polyfill-only bug and not a problem with the spec text, because three other implementations (SpiderMonkey, temporal_rs, Fullcalendar polyfill) all print the correct results:
P1Y
1.0001141552511414
I caught this while writing snapshot tests. This means that it isn't currently covered by test262, or it would have been caught already.