import { DateAdapter, DateAdapterBase, DateAdapterCTor, DateInput, DateTime, IRunNextArgs, } from '@rschedule/core'; export interface IRunArgs { start?: DateTime; end?: DateTime; take?: number; reverse?: boolean; } export declare type OccurrenceGeneratorRunResult = Iterator< DateTime, undefined, IRunNextArgs | undefined > & { [Symbol.iterator](): Iterator; }; export declare abstract class OccurrenceGenerator { /** Returns the first occurrence or, if there are no occurrences, null. */ get firstDate(): DateAdapter | null; /** If generator is infinite, returns `null`. Otherwise returns the end date */ get lastDate(): DateAdapter | null; protected get dateAdapter(): DateAdapterCTor; abstract readonly isInfinite: boolean; abstract readonly hasDuration: boolean; /** * The maximum duration of this generators occurrences. Necessary * as part of the logic processing. By default it is 0. */ readonly maxDuration: number; readonly timezone: string | null; private _firstDate?; private _lastDate?; private getMaxDuration; constructor(args?: { timezone?: string | null; maxDuration?: number }); pipe(...operators: OperatorFnOutput[]): OccurrenceGenerator; abstract set( prop: 'timezone', value: string | null, options?: { keepLocalTime?: boolean; }, ): OccurrenceGenerator; /** * **!!Advanced Use Only!!** * * use `occurrences()` instead */ abstract _run(args?: IRunArgs): OccurrenceGeneratorRunResult; /** * Processes the object's rules/dates and returns an iterable for the occurrences. * * Options object: * - `start` the date to begin iteration on * - `end` the date to end iteration on * - `take` the max number of dates to take before ending iteration * - `reverse` whether to iterate in reverse or not * * Examples: * * ``` * const iterator = schedule.occurrences({ start: new Date(), take: 5 }); * for (const date of iterator) { * // do stuff * } * iterator.toArray() // returns Date array * iterator.next().value // returns next Date * ``` * */ occurrences(args?: IOccurrencesArgs): OccurrenceIterator; /** * Iterates over the object's occurrences and bundles them into collections * with a specified granularity (default is `"YEARLY"`). Make sure to * read about each option & combination of options below. * * Options object: * - start?: DateAdapter * - end?: DateAdapter * - take?: number * - reverse?: NOT SUPPORTED * - granularity?: CollectionsGranularity * - weekStart?: DateAdapter.Weekday * - skipEmptyPeriods?: boolean * * Returned `Collection` object: * * - `dates` property containing an array of DateAdapter objects. * - `granularity` property containing the granularity. * - `CollectionsGranularity` === `RuleOptions.Frequency`. * - default is `"YEARLY"` * - `periodStart` property containing a DateAdapter equal to the period's * start time. * - `periodEnd` property containing a DateAdapter equal to the period's * end time. * * #### Details: * * `collections()` always returns full periods. This means that the `start` argument is * transformed to be the start of whatever period the `start` argument is in, and the * `end` argument is transformed to be the end of whatever period the `end` argument is * in. * * - Example: with granularity `"YEARLY"`, the `start` argument will be transformed to be the * start of the year passed in the `start` argument, and the `end` argument will be transformed * to be the end of the year passed in the `end` argument. * * By default, the `periodStart` value of `Collection` objects produced by this method increments linearly. * This means the returned `Collection#dates` property may have length 0. This can be changed by * passing the `skipEmptyPeriods: true` option, in which case the `periodStart` from one collection to the * next can "jump". * * - Example 1: if your object's first occurrence is 2019/2/1 (February 1st) and you call * `collection({skipEmptyPeriods: true, granularity: 'DAILY', start: new Date(2019,0,1)})` * (so starting on January 1st), the first Collection produced will have a `periodStart` in February. * * - Example 2: if your object's first occurrence is 2019/2/1 (February 1st) and you call * `collection({granularity: 'DAILY', start: new Date(2019,0,1)})` * (so starting on January 1st), the first collection produced will have a `Collection#periodStart` * of January 1st and have `Collection#dates === []`. Similarly, the next 30 collections produced * (Jan 2nd - 31st) will all contain an empty array for the `dates` property. Then the February 1st * `Collection` will contain dates. * * When giving a `take` argument to `collections()`, you are specifying * the number of `Collection` objects to return (rather than occurrences). * * When choosing a granularity of `"WEEKLY"`, the `weekStart` option is required. * * When choosing a granularity of `"MONTHLY"`: * * - If the `weekStart` option *is not* present, will generate collections with * the `periodStart` and `periodEnd` at the beginning and end of each month. * * - If the `weekStart` option *is* present, will generate collections with the * `periodStart` equal to the start of the first week of the month, and the * `periodEnd` equal to the end of the last week of the month. This behavior could be * desired when rendering opportunities in a calendar view, where the calendar renders * full weeks (which may result in the calendar displaying dates in the * previous or next months). * */ collections(args?: ICollectionsArgs): CollectionIterator; /** * Returns true if an occurrence starts on or between the provided start/end * datetimes. If the `excludeEnds` option is provided, then occurrences * equal to the start/end times are ignored. * * If the occurrence generator has a duration, and `excludeEnds !== true`, * and a `maxDuration` argument is supplied (either in the constructor or * here), then any occurrence that's time overlaps with the start/end times * return true. */ occursBetween( startInput: DateInput, endInput: DateInput, options?: { excludeEnds?: boolean; maxDuration?: number; }, ): boolean; /** * Checks to see if an occurrence exists which equals the given date. * * If this occurrence generator has a duration, and a `maxDuration` * argument is supplied (either in the constructor or here), * then `occursOn()` will check to see if an occurrence is happening * during the given datetime. * * Additionally, if this occurrence generator has a duration, then a maxDuration * argument must be provided. This argument should be the max number of milliseconds * that an occurrence's duration can be. When you create an occurrence * generator, you can specify the maxDuration at that time. */ occursOn(args: { date: DateInput; maxDuration?: number }): boolean; /** * Checks to see if an occurrence exists with a weekday === the `weekday` argument. * **If there are infinite occurrences, you must include a `before` argument with * the `weekday` argument.** Does not currently consider occurrence duration. * * Optional arguments: * * - `after` and `before` arguments can be provided which limit the * possible occurrences to ones *after or equal* or *before or equal* the given dates. * - If `excludeEnds` is `true`, then the after/before arguments become exclusive rather * than inclusive. */ occursOn(args: { weekday: DateAdapter.Weekday; after?: DateInput; before?: DateInput; excludeEnds?: boolean; }): boolean; /** * Returns true if an occurrence starts after the provided datetime. * If the `excludeStart` option is provided, then occurrences * equal to the provided datetime are ignored. * * If the occurrence generator has a duration, and `excludeStart !== true`, * and a `maxDuration` argument is supplied (either in the constructor or * here), then any occurrence that's end time is after/equal to the provided * datetime return true. */ occursAfter( date: DateInput, options?: { excludeStart?: boolean; maxDuration?: number; }, ): boolean; /** * Returns true if an occurrence starts before the provided datetime. * If the `excludeStart` option is provided, then occurrences * equal to the provided datetime are ignored. * * If the occurrence generator has a duration, and `excludeStart` is * also provided, then this will only return true if an occurrence * both starts and ends before the provided datetime. */ occursBefore( date: DateInput, options?: { excludeStart?: boolean; }, ): boolean; protected normalizeOccurrencesArgs( rawArgs: IOccurrencesArgs, ): { start: DateTime | undefined; end: DateTime | undefined; take?: number | undefined; reverse?: boolean | undefined; }; protected normalizeCollectionsArgs( rawArgs: ICollectionsArgs, ): { start: DateTime | undefined; end: DateTime | undefined; granularity?: CollectionsGranularity; weekStart?: DateAdapter.Weekday; skipEmptyPeriods?: boolean; take?: number; reverse?: boolean; }; protected normalizeOccursOnArgs(rawArgs?: { date?: DateInput; weekday?: DateAdapter.Weekday; after?: DateInput; before?: DateInput; excludeEnds?: boolean; excludeDates?: Array; maxDuration?: number; }): { date: DateTime | undefined; after: DateTime | undefined; before: DateTime | undefined; excludeDates: DateTime[] | undefined; weekday?: DateAdapter.Weekday; excludeEnds?: boolean; maxDuration?: number; }; protected normalizeRunArgs( args: IRunArgs, ): { start: DateTime | undefined; end: DateTime | undefined; take?: number | undefined; reverse?: boolean | undefined; }; protected normalizeDateInput( date: T, ): T extends undefined ? undefined : DateTime; protected normalizeDateInputToAdapter(date: DateInput): DateAdapter; protected normalizeDateInputToAdapter(date?: DateInput): undefined; protected normalizeRunOutput(date: DateTime): DateTime; } export interface IOccurrencesArgs { start?: DateInput; end?: DateInput; take?: number; reverse?: boolean; } export interface IOccurrencesNextArgs { /** * Moves the iterator state forward so that it is equal * to or past the given date. The provided date *must* * be greater than the last yielded date (or, when iterating * in reverse, it must be smaller). This is more efficent then repeatedly * iterating and throwing away values until the desired date * is reached. */ skipToDate?: DateInput; } export declare class OccurrenceIterator< G extends ReadonlyArray = ReadonlyArray< OccurrenceGenerator > > implements Iterator< DateAdapter & { generators: G; }, undefined, IOccurrencesNextArgs | undefined > { [Symbol.iterator]: () => Generator< DateAdapterBase & { generators: G; }, undefined, unknown >; private iterable; private args; private readonly iterator; private readonly isInfinite; private occurrenceIterator; private normalizeRunArgs; private normalizeDateInput; private normalizeDateOutput; constructor(iterable: OccurrenceGenerator, args: IRunArgs); next( args?: IOccurrencesNextArgs, ): IteratorResult< DateAdapter & { generators: G; }, undefined >; toArray(): Array< DateAdapter & { generators: G; } >; } export declare type CollectionsGranularity = | 'millisecond' | 'second' | 'minute' | 'hour' | 'day' | 'week' | 'month' | 'year'; export declare class Collection< G extends ReadonlyArray = ReadonlyArray< OccurrenceGenerator > > { readonly dates: (DateAdapter & { generators: G; })[]; readonly granularity: CollectionsGranularity; readonly periodStart: DateAdapter & { generators: G; }; readonly periodEnd: DateAdapter & { generators: G; }; constructor( dates: (DateAdapter & { generators: G; })[], granularity: CollectionsGranularity, periodStart: DateAdapter & { generators: G; }, periodEnd: DateAdapter & { generators: G; }, ); } export interface ICollectionsArgs extends IOccurrencesArgs { granularity?: CollectionsGranularity; weekStart?: DateAdapter.Weekday; skipEmptyPeriods?: boolean; } export interface ICollectionsRunArgs extends IRunArgs { granularity?: CollectionsGranularity; weekStart?: DateAdapter.Weekday; skipEmptyPeriods?: boolean; } export declare class CollectionIterator< G extends ReadonlyArray = ReadonlyArray< OccurrenceGenerator > > implements Iterator, undefined, undefined> { readonly granularity: CollectionsGranularity; readonly weekStart?: DateAdapter.Weekday; readonly startDate: DateAdapter | null; [Symbol.iterator]: () => IterableIterator>; private iterable; private args; private iterator; private normalizeDateOutput; private collectionIterator; private getPeriod; private incrementPeriod; private occurrenceIterator; constructor(iterable: OccurrenceGenerator, args: ICollectionsRunArgs); next(): IteratorResult, any>; /** * While `next()` and `[Symbol.iterator]` both share state, * `toArray()` does not share state and always returns the whole * collections array. */ toArray(): Collection[]; } export declare type OperatorFn = () => OperatorFnOutput; export declare type OperatorFnOutput = (options: IOperatorConfig) => Operator; export interface IOperatorConfig { readonly timezone: string | null; readonly base?: OccurrenceGenerator; } export declare abstract class Operator extends OccurrenceGenerator { readonly streams: ReadonlyArray; readonly config: IOperatorConfig; readonly isInfinite: boolean; readonly hasDuration: boolean; readonly timezone: string | null; constructor( streams: ReadonlyArray, config: IOperatorConfig, ); protected abstract calculateIsInfinite(): boolean; protected abstract calculateHasDuration(): boolean; protected normalizeDateInput(date: DateInput): DateTime; protected normalizeDateInput(date?: DateInput): undefined; protected normalizeRunOutput(date: DateTime): DateTime; }