Skip to content

Polyfill: Coverage gap in calendarToIsoDate #3217

@catamorphism

Description

@catamorphism

I'm reviewing the codecov.io reports for the polyfill. It reports the following code as uncovered:

https://github.com/tc39/proposal-temporal/blob/main/polyfill/lib/calendar.mjs#L937-L953

The code is:

          if (increment > 1) {
            // If the estimate overshot the target, try again with a smaller increment
            // in the reverse direction.
            increment /= 2;
          } else {
            // Increment is 1, and neither the previous estimate nor the new
            // estimate is correct. The only way that can happen is if the
            // original date was an invalid value that will be constrained or
            // rejected here.
            if (overflow === 'reject') {
              throw new RangeErrorCtor(`Can't find ISO date from calendar date: ${JSONStringify({ ...originalDate })}`);
            } else {
              // To constrain, pick the earliest value
              const order = this.compareCalendarDates(roundtripEstimate, oldRoundtripEstimate);
              // If current value is larger, then back up to the previous value.
              if (order > 0) isoEstimate = addDaysISO(isoEstimate, -1);
              sign = 0;
            }
          }

This only runs if the estimated ISO date is more than a month off from the roundtripped ISO date, even after the calculations in the code just preceding the while loop. There are test262 cases where the estimate is off by days, but not months or years. I don't know right now how to construct an example that triggers this code, so I'm recording it here to be worked on in the future.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions