Skip to content

Test coverage gap in NudgeToCalendarUnit #3235

@catamorphism

Description

@catamorphism

codecov reports the following code (currently lines 3313-3330 of ecmascript.mjs) as a coverage gap:

else if (sign == -1) {
    if (!(nudgeWindow.endEpochNs.leq(destEpochNs) && destEpochNs.leq(nudgeWindow.startEpochNs))) {
      // Retry nudge window if it's out of bounds
      nudgeWindow = ComputeNudgeWindow(
        sign,
        duration,
        originEpochNs,
        isoDateTime,
        timeZone,
        calendar,
        increment,
        unit,
        true
      );
      assert(
        nudgeWindow.endEpochNs.leq(destEpochNs) && destEpochNs.leq(nudgeWindow.startEpochNs),
        `${unit} was 0 days long`
      );
      didExpandCalendarUnit = true;

and indeed, we don't have tests that exercise the case where the duration is negative and we need to retry the nudge window.

I haven't been able to construct an example to exercise this code. In the (sign == 1) case, the nudge window may need to be retried if (for example) the duration being added could be expressed as either 1 month, 10 hours or 29 days, 10 hours (such as when the relativeTo date is 2020-01-31). The same case doesn't seem to happen going backwards as the duration is unambiguously a month.

However, I haven't convinced myself that this is always true.

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