Skip to content

Assertion failure in year-and-a-bit durations relative to leap day #3168

@ptomato

Description

@ptomato

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:

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions