@karmaniverous/rrstack
    Preparing search index...

    Class RRStack

    Library entry point.

    • Re-export RRStack and public types.
    • Type-only exports to keep runtime lean.
    Index

    Constructors

    Properties

    Normalized, frozen options. Mutate via timezone, rules, or update.

    Accessors

    • get timezone(): string

      Get the current IANA timezone id (unbranded string).

      Returns string

    • set timezone(next: string): void

      Set the timezone and recompile.

      Parameters

      • next: string

        IANA timezone id (validated).

      Returns void

      If the timezone is invalid.

    Methods

    • Insert a rule at a specific index (or append when index is omitted). Delegates to the rules setter (single recompile). When called with no arguments, inserts a default span rule: { effect: 'active', options: {} }.

      Parameters

      • Optionalrule: RuleJson
      • Optionalindex: number

      Returns void

    • Move a rule to the bottom (last index).

      Parameters

      • i: number

      Returns void

    • Describe a rule by index as human-readable text. Leverages rrule.toText() plus effect and duration phrasing. *

      Parameters

      Returns string

      RangeError if index is out of bounds; TypeError if not an integer.

      const text = stack.describeRule(0, { includeTimeZone: true, includeBounds: true });
      // e.g., "Active for 1 hour: every day at 5:00 (timezone UTC) [from 2024-01-10T00:00:00Z]"
    • Move a rule down by one (toward the end). No-op if already at the bottom.

      Parameters

      • i: number

      Returns void

    • Format an instant using this stack's configured timezone and time unit.

      • In 'ms' mode, t is interpreted as milliseconds since epoch.
      • In 's' mode, t is interpreted as integer seconds since epoch.

      Parameters

      • t: number

        Instant in the configured unit.

      • Optionalopts: { format?: string; locale?: string }

        Optional formatting:

        • format?: Luxon toFormat string (e.g., 'yyyy-LL-dd HH:mm').
        • locale?: BCP-47 locale tag applied prior to formatting.

      Returns string

      A string representation (ISO by default).

      stack.formatInstant(Date.UTC(2024, 0, 2, 5, 30, 0)); // '2024-01-02T05:30:00Z' (UTC)
      stack.formatInstant(ms, { format: 'yyyy-LL-dd HH:mm' }); // '2024-01-02 05:30'
    • Compute effective active bounds across all rules.

      Returns { empty: boolean; end?: number; start?: number }

      { start?: number; end?: number; empty: boolean }

      • start and/or end are omitted for open-sided coverage.
      • empty indicates no active coverage.
      const stack = new RRStack({
      timezone: 'UTC',
      rules: [{
      effect: 'active',
      duration: { hours: 1 },
      options: { freq: 'daily', byhour: [5], byminute: [0], bysecond: [0], starts: Date.UTC(2024, 0, 10, 0, 0, 0) },
      }],
      });
      const b = stack.getEffectiveBounds();
      // b.start is 2024-01-10T05:00:00Z (number); b.end is undefined (open end)
    • Stream contiguous status segments over [from, to). *

      Parameters

      • from: number

        Start of the window (inclusive), in the configured unit.

      • to: number

        End of the window (exclusive), in the configured unit.

      • Optionalopts: { limit?: number }

        Optional settings:

        • limit?: number — maximum number of segments to yield; throws if more would be produced (no silent truncation).

      Returns Iterable<{ end: number; start: number; status: InstantStatus }>

      An iterable of { start, end, status } entries. Memory-bounded and stable for long windows.

      for (const seg of stack.getSegments(from, to)) {
      // { start: number; end: number; status: 'active' | 'blackout' }
      }
      const segs: Array<{ start: number; end: number; status: 'active' | 'blackout' }> = [];
      try {
      for (const seg of stack.getSegments(from, to, { limit: 1000 })) {
      segs.push(seg);
      }
      } catch (err) {
      // If more than 1000 segments would be produced, an Error is thrown.
      // Consider reducing the window or processing in chunks (e.g., day/week).
      }

      Note: The iterator is streaming and memory-bounded, but the number of segments can be large when many rules overlap across long windows. Use the limit option to make this explicit, or query in smaller chunks for real-time UIs.

    • Determine whether the stack is active at t.

      Parameters

      • t: number

        Timestamp in the configured unit.

      Returns boolean

      true when active; false when blackout.

    • Remove the rule at the specified index. Delegates to the rules setter (single recompile).

      Parameters

      • i: number

        Zero-based index of the rule to remove.

      Returns void

      TypeError if i is not an integer; RangeError if out of range.

    • Subscribe to post‑mutation notifications. The listener is invoked exactly once after a successful state change (after recompile). The constructor initialization does not trigger notifications.

      Parameters

      Returns () => void

      Unsubscribe function.

    • Swap two rules by index (no-op if indices are equal).

      Parameters

      • i: number
      • j: number

      Returns void

    • Move a rule up by one (toward index 0). No-op if already at the top.

      Parameters

      • i: number

      Returns void

    • Ingest a partial RRStackOptions JSON with version/unit handling, replacements, and notices.

      • Applies timezone, defaultEffect, rules, and timeUnit in one pass.
      • Version pipeline (upgrade-config) executes first; defaults: • onVersionUp: 'off', onVersionDown: 'error', onVersionInvalid: 'error'.
      • timeUnit change: • If rules provided: replace rules as-is (assumed in new unit). • If not: convert retained rules' options.starts/options.ends between units (ms ↔ s).
      • Recompiles exactly once on success.

      Parameters

      Returns readonly Notice[]

    • Validate an IANA timezone id.

      Parameters

      • tz: string

        Candidate IANA timezone string.

      Returns boolean

      True if recognized by the host ICU/Intl data.