import { DateTime } from '@rschedule/core'; import { IOperatorConfig, IRunArgs, OccurrenceGeneratorRunResult, Operator, OperatorFnOutput, } from '../occurrence-generator'; 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 { readonly splitFn: (dateTime: DateTime) => DateTime[]; readonly maxDuration: number; constructor( args: { maxDuration?: number; splitFn: (dateTime: DateTime) => DateTime[]; }, config: IOperatorConfig, ); /** Not actually used but necessary for IRunnable interface */ set(_: 'timezone', value: string | null): SplitDurationOperator; _run(args?: IRunArgs): OccurrenceGeneratorRunResult; protected calculateIsInfinite(): boolean; protected calculateHasDuration(): boolean; protected splitDate(date: DateTime, reverse: boolean): DateTime[]; }