Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mark BalancePossiblyInfiniteTimeDuration and CreateTimeDurationRecord as infallible #2611

Merged
merged 3 commits into from
Aug 10, 2023

Commits on Aug 10, 2023

  1. Editorial: CreateTimeDurationRecord is infallble in BalancePossiblyIn…

    …finiteTimeDuration
    
    Infinite values are handled explicitly and return an overflow indicator
    and all components have the same sign. Therefore it's not possible for
    CreateTimeDurationRecord to throw.
    anba authored and ptomato committed Aug 10, 2023
    Configuration menu
    Copy the full SHA
    23fc07c View commit details
    Browse the repository at this point in the history
  2. Editorial: Handle days overflow in BalancePossiblyInfiniteTimeDuratio…

    …nRelative
    
    Return an overflow marker when `𝔽(days)` is infinite. Strictly speaking
    a normative change, but can only happen when there are over 1e292
    iterations in NanosecondsToDays.
    
    When passing a finite `𝔽(days)` to CreateTimeDurationRecord,
    CreateTimeDurationRecord can't fail anymore, so it's now marked as
    infallible.
    
    Example how to trigger infinite days in theory:
    ```js
    let cal = new class extends Temporal.Calendar {
      #dateUntil = 0;
    
      dateUntil(one, two, options) {
        if (this.#dateUntil++ === 0) {
          return Temporal.Duration.from({days: Number.MAX_VALUE})
        }
        return super.dateUntil(one, two, options);
      }
    
      #dateAdd = 0;
    
      dateAdd(date, duration, options) {
        if (this.#dateAdd++ === 0) {
          return date;
        }
        if (duration.days > 1) {
          return date;
        }
        return super.dateAdd(date, duration, options)
      }
    }("iso8601");
    
    let tz = new class extends Temporal.TimeZone {
      #getPossibleInstantsFor = 0n;
    
      getPossibleInstantsFor(dateTime) {
        if (this.#getPossibleInstantsFor++ < 10n**292n) {
          return [new Temporal.Instant(0n)];
        }
        return super.getPossibleInstantsFor(dateTime);
      }
    }("UTC");
    
    let zdt = new Temporal.ZonedDateTime(0n, tz, cal);
    let d = Temporal.Duration.from({nanoseconds: 1});
    let r = d.total({unit: "days", relativeTo: zdt})
    ```
    anba authored and ptomato committed Aug 10, 2023
    Configuration menu
    Copy the full SHA
    cd13782 View commit details
    Browse the repository at this point in the history
  3. Editorial: Assert CreateTimeDurationRecord is called with valid durat…

    …ion values
    
    All callers to CreateTimeDurationRecord pass valid duration values, so
    we can assert this in CreateTimeDurationRecord instead of throwing an
    error.
    anba authored and ptomato committed Aug 10, 2023
    Configuration menu
    Copy the full SHA
    1bd6156 View commit details
    Browse the repository at this point in the history