import { type CalendarDate, type DateRange } from '../date'; import { type DateRRuleInstance } from './date.rrule'; import { type RRuleLines, type RRuleStringLineSet } from './date.rrule.parse'; import { type TimezoneString } from '@dereekb/util'; /** * Marks an entity as potentially recurring by carrying optional * {@link ModelRecurrenceInfo} and a convenience boolean flag. */ export interface RecurrenceModel { /** * Detailed recurrence metadata; undefined when the model does not recur. */ recur?: ModelRecurrenceInfo; /** * Quick check for whether this model has active recurrence rules. */ recurs: boolean; } /** * Serializable recurrence metadata stored alongside a model, containing the * RRule string, the computed start/end of the recurrence window, and a * "forever" flag. Implements {@link DateRange} for easy integration with * date-range utilities. */ export interface ModelRecurrenceInfo extends DateRange { /** * Timezone the rule is a part of. Required for RRules that have timezone-sensitive implementations. */ timezone?: TimezoneString; /** * RRules for this recurrence. */ rrule: RRuleLines; /** * First instance of the recurrence. */ start: Date; /** * Final instance of the recurrence. */ end: Date; /** * True if the recurrence has no end. */ forever?: boolean; } /** * Input used to create or update recurrence on a model, before it is * expanded into a full {@link ModelRecurrenceInfo}. */ export interface ModelRecurrenceStart { /** * Lines/set of rules to follow. */ rrule: RRuleStringLineSet; /** * Date information for the recurrence. */ date: CalendarDate; /** * Timezone the recurrence should follow. */ timezone?: TimezoneString; } /** * Stateless utility for converting between recurrence input * ({@link ModelRecurrenceStart}) and the indexed storage form * ({@link ModelRecurrenceInfo}). */ export declare class ModelRecurrenceInfoUtility { /** * Expands a {@link ModelRecurrenceStart} into a fully resolved * {@link ModelRecurrenceInfo} by parsing the RRule, computing the * recurrence date range, and populating the `forever` flag. * * @param update - The recurrence start input to expand. * @returns A new {@link ModelRecurrenceInfo} with computed start, end, and forever fields. * * @example * ```ts * const info = ModelRecurrenceInfoUtility.expandModelRecurrenceStartToModelRecurrenceInfo({ * rrule: ['FREQ=WEEKLY;COUNT=10'], * date: { startsAt: new Date(), duration: 3600000 }, * timezone: 'America/Chicago' * }); * ``` */ static expandModelRecurrenceStartToModelRecurrenceInfo(update: ModelRecurrenceStart): ModelRecurrenceInfo; /** * Creates a {@link DateRRuleInstance} from stored {@link ModelRecurrenceInfo} * and a reference {@link CalendarDate}, allowing further expansion or * recurrence queries. * * @param info - Stored recurrence metadata. * @param date - Reference calendar date providing startsAt and duration. * @returns A new {@link DateRRuleInstance} ready for expansion. * * @example * ```ts * const instance = ModelRecurrenceInfoUtility.makeDateRRuleInstance( * model.recur, * { startsAt: new Date(), duration: 3600000 } * ); * const nextDate = instance.nextRecurrenceDate(); * ``` */ static makeDateRRuleInstance(info: ModelRecurrenceInfo, date: CalendarDate): DateRRuleInstance; }