UNPKG

rrule-rust

Version:

RRule implementation for browsers and Node.js written in Rust

125 lines (124 loc) 4.09 kB
import { DateTime, type Time, type DateTimeLike, type DateLike } from './datetime'; /** * Options for creating an RDate instance. */ export interface RDateOptions<DT extends DateTime<Time> | DateTime<undefined>> { /** Array of date/time values to include in recurrence */ values: DT[]; /** Optional timezone identifier (e.g., "America/New_York") */ tzid?: string; } /** * Plain object representation of RDate. */ export interface RDateLike<DT extends DateTimeLike | DateLike> { /** Array of date/time values to include in recurrence */ values: DT[]; /** Optional timezone identifier (e.g., "America/New_York") */ tzid?: string; } /** * Represents recurrence dates (RDATE property) for a recurrence rule. * * RDate specifies additional date/time values that should be included in the * recurrence set. This is useful for adding extra occurrences that don't fit * the regular recurrence pattern. * * @example * ```typescript * // Create with single date * const rdate1 = new RDate(DateTime.date(2024, 1, 15)); * * // Create with multiple dates * const rdate2 = new RDate([ * DateTime.date(2024, 1, 15), * DateTime.date(2024, 1, 22) * ]); * * // Create with timezone * const rdate3 = new RDate({ * values: [DateTime.local(2024, 1, 15, 9, 0, 0)], * tzid: "America/New_York" * }); * ``` */ export declare class RDate<DT extends DateTime<Time> | DateTime<undefined>> { /** Array of date/time values to include in 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: RDateOptions<DT>); /** * Creates an RDate instance from a plain object representation. * * @param plain - Plain object with date/time values and optional timezone * @returns A new RDate instance * * @example * ```typescript * const plain = { * values: [ * { year: 2024, month: 1, day: 15 }, * { year: 2024, month: 1, day: 22 } * ], * tzid: "America/New_York" * }; * const rdate = RDate.fromPlain(plain); * ``` */ static fromPlain(plain: RDateLike<DateTimeLike>): RDate<DateTime<Time>>; static fromPlain(plain: RDateLike<DateLike>): RDate<DateTime<undefined>>; /** * Creates a new RDate instance with a different timezone. * * @param tzid - Timezone identifier (e.g., "America/New_York") or undefined * @returns A new RDate instance with the specified timezone * * @example * ```typescript * const rdate = new RDate([DateTime.date(2024, 1, 15)]); * const withTz = rdate.setTzid("America/New_York"); * ``` */ setTzid(tzid: string | undefined): RDate<DT>; /** * Creates a new RDate instance with different date/time values. * * @param datetimes - Array of new date/time values * @returns A new RDate instance with the specified values * * @example * ```typescript * const rdate = new RDate([DateTime.date(2024, 1, 15)]); * const updated = rdate.setValues([ * DateTime.date(2024, 1, 15), * DateTime.date(2024, 1, 22) * ]); * ``` */ setValues<NDT extends DateTime<Time> | DateTime<undefined>>(datetimes: NDT[]): RDate<NDT>; /** * Converts the RDate instance to a plain object representation. * * @returns A plain object with date/time values and optional timezone * * @example * ```typescript * const rdate = new RDate( * [DateTime.date(2024, 1, 15), DateTime.date(2024, 1, 22)], * "America/New_York" * ); * const plain = rdate.toPlain(); * // { * // values: [ * // { year: 2024, month: 1, day: 15 }, * // { year: 2024, month: 1, day: 22 } * // ], * // tzid: "America/New_York" * // } * ``` */ toPlain(): DT extends DateTime<Time> ? RDateLike<DateTimeLike> : RDateLike<DateLike>; }