import { DateAdapter } from '../date-adapter'; import { DateTime } from '../date-time'; import { IOperatorConfig, Operator, OperatorFnOutput } from './interface'; declare const SPLIT_DURATION_OPERATOR_ID: unique symbol; export declare class SplitDurationOperatorError extends Error { } /** * An operator function which takes an occurrence stream with * `hasDuration === true` and passes occurrences through a splitting * function. One usecase for this operator is to dynamically break up * occurrences with a large duration into several smaller occurrences. * * You must provide a `maxDuration` argument that represents the * maximum possible duration for a single occurrence. If this * duration is exceeded, a `SplitDurationOperatorError` will be * thrown. * * - For your convenience, you can globally set a default * `SplitDurationOperator#maxDuration` via * `RScheduleConfig.SplitDurationOperator.defaultMaxDuration`. * * Usage example: * * ```typescript * const MILLISECONDS_IN_HOUR = 1000 * 60 * 60; * * const splitFn = (date: DateTime) => { * if (date.duration > MILLISECONDS_IN_HOUR) { * const diff = date.duration! / 2; * * return [ * date.set('duration', diff), * date.add(diff, 'millisecond').set('duration', diff), * ]; * } * * return [date]; * }; * * const dates = new Dates({ * dates: [ * new StandardDateAdapter(new Date(2010, 10, 10, 13), { duration: MILLISECONDS_IN_HOUR * 1 }), * new StandardDateAdapter(new Date(2010, 10, 11, 13), { duration: MILLISECONDS_IN_HOUR * 2 }), * ], * dateAdpter: StandardDateAdapter, * }).pipe( * splitDuration({ * splitFn, * maxDuration: MILLISECONDS_IN_HOUR * 1 * }) * ) * * expect(dates.occurrences().toArray()).toEqual([ * new StandardDateAdapter(new Date(2010, 10, 10, 13), { duration: MILLISECONDS_IN_HOUR * 1 }), * new StandardDateAdapter(new Date(2010, 10, 11, 13), { duration: MILLISECONDS_IN_HOUR * 1 }), * new StandardDateAdapter(new Date(2010, 10, 11, 14), { duration: MILLISECONDS_IN_HOUR * 1 }), * ]) * ``` */ export declare function splitDuration(args: { maxDuration?: number; splitFn: (dateTime: DateTime) => DateTime[]; }): OperatorFnOutput; export declare class SplitDurationOperator extends Operator { static isSplitDurationOperator(object: unknown): object is SplitDurationOperator; readonly splitFn: (dateTime: DateTime) => DateTime[]; readonly maxDuration: number; protected readonly [SPLIT_DURATION_OPERATOR_ID] = true; constructor(args: { maxDuration?: number; splitFn: (dateTime: DateTime) => DateTime[]; }, config: IOperatorConfig); /** Not actually used but necessary for IRunnable interface */ set(_: 'timezone', value: string | null): SplitDurationOperator; protected calculateIsInfinite(): boolean; protected calculateHasDuration(): boolean; protected splitDate(date: DateTime, reverse: boolean): DateTime[]; } export {}; //# sourceMappingURL=split-duration.operator.d.ts.map