rrule-rust
Version:
RRule implementation for browsers and Node.js written in Rust
125 lines (124 loc) • 4.15 kB
TypeScript
import { DateTime, type Time, type DateTimeLike, type DateLike } from './datetime';
/**
* Options for creating an ExDate instance.
*/
export interface ExDateOptions<DT extends DateTime<Time> | DateTime<undefined>> {
/** Array of date/time values to exclude from recurrence */
values: DT[];
/** Optional timezone identifier (e.g., "America/New_York") */
tzid?: string;
}
/**
* Plain object representation of ExDate.
*/
export interface ExDateLike<DT extends DateTimeLike | DateLike> {
/** Array of date/time values to exclude from recurrence */
values: DT[];
/** Optional timezone identifier (e.g., "America/New_York") */
tzid?: string;
}
/**
* Represents exception dates (EXDATE property) for a recurrence rule.
*
* ExDate specifies date/time values that should be excluded from the
* recurrence set. This is useful for marking exceptions like holidays
* or cancelled events in a recurring series.
*
* @example
* ```typescript
* // Create with single date
* const exdate1 = new ExDate(DateTime.date(2024, 1, 15));
*
* // Create with multiple dates
* const exdate2 = new ExDate([
* DateTime.date(2024, 1, 15),
* DateTime.date(2024, 1, 22)
* ]);
*
* // Create with timezone
* const exdate3 = new ExDate({
* values: [DateTime.local(2024, 1, 15, 9, 0, 0)],
* tzid: "America/New_York"
* });
* ```
*/
export declare class ExDate<DT extends DateTime<Time> | DateTime<undefined> = DateTime<Time>> {
/** Array of date/time values to exclude from recurrence */
readonly values: DT[];
/** Optional timezone identifier (e.g., "America/New_York") */
readonly tzid?: string;
constructor(values: DT, tzid?: string);
constructor(values: DT[], tzid?: string);
constructor(options: ExDateOptions<DT>);
/**
* Creates an ExDate instance from a plain object representation.
*
* @param plain - Plain object with date/time values and optional timezone
* @returns A new ExDate instance
*
* @example
* ```typescript
* const plain = {
* values: [
* { year: 2024, month: 1, day: 15 },
* { year: 2024, month: 1, day: 22 }
* ],
* tzid: "America/New_York"
* };
* const exdate = ExDate.fromPlain(plain);
* ```
*/
static fromPlain(plain: ExDateLike<DateTimeLike>): ExDate<DateTime<Time>>;
static fromPlain(plain: ExDateLike<DateLike>): ExDate<DateTime<undefined>>;
/**
* Creates a new ExDate instance with a different timezone.
*
* @param tzid - Timezone identifier (e.g., "America/New_York") or undefined
* @returns A new ExDate instance with the specified timezone
*
* @example
* ```typescript
* const exdate = new ExDate([DateTime.date(2024, 1, 15)]);
* const withTz = exdate.setTzid("America/New_York");
* ```
*/
setTzid(tzid: string | undefined): ExDate<DT>;
/**
* Creates a new ExDate instance with different date/time values.
*
* @param datetimes - Array of new date/time values
* @returns A new ExDate instance with the specified values
*
* @example
* ```typescript
* const exdate = new ExDate([DateTime.date(2024, 1, 15)]);
* const updated = exdate.setValues([
* DateTime.date(2024, 1, 15),
* DateTime.date(2024, 1, 22)
* ]);
* ```
*/
setValues<NDT extends DateTime<Time> | DateTime<undefined>>(datetimes: NDT[]): ExDate<NDT>;
/**
* Converts the ExDate instance to a plain object representation.
*
* @returns A plain object with date/time values and optional timezone
*
* @example
* ```typescript
* const exdate = new ExDate(
* [DateTime.date(2024, 1, 15), DateTime.date(2024, 1, 22)],
* "America/New_York"
* );
* const plain = exdate.toPlain();
* // {
* // values: [
* // { year: 2024, month: 1, day: 15 },
* // { year: 2024, month: 1, day: 22 }
* // ],
* // tzid: "America/New_York"
* // }
* ```
*/
toPlain(): DT extends DateTime<Time> ? ExDateLike<DateTimeLike> : ExDateLike<DateLike>;
}