UNPKG

rrule-rust

Version:

RRule implementation for browsers and Node.js written in Rust

111 lines (110 loc) 3.74 kB
import { DateTime, type Time, type DateTimeLike, type DateLike } from './datetime'; /** * Options for creating a DtStart instance. */ export interface DtStartOptions<DT extends DateTime<Time> | DateTime<undefined>> { /** The start date/time value */ value: DT; /** Optional timezone identifier (e.g., "America/New_York") */ tzid?: string; } /** * Plain object representation of DtStart. */ export interface DtStartLike<DT extends DateTimeLike | DateLike> { /** The start date/time value */ value: DT; /** Optional timezone identifier (e.g., "America/New_York") */ tzid?: string; } /** * Represents the start date/time for a recurrence rule (DTSTART property). * * DtStart defines when the recurrence pattern begins. It can optionally * include a timezone identifier for proper timezone handling. * * @example * ```typescript * // Create with DateTime and timezone * const dtstart = new DtStart( * DateTime.local(2024, 1, 15, 9, 0, 0), * "America/New_York" * ); * * // Create with options object * const dtstart2 = new DtStart({ * value: DateTime.date(2024, 1, 15), * tzid: "Europe/London" * }); * ``` */ export declare class DtStart<DT extends DateTime<Time> | DateTime<undefined> = DateTime<Time>> { /** The start date/time value */ readonly value: DT; /** Optional timezone identifier (e.g., "America/New_York") */ readonly tzid?: string; constructor(value: DT, tzid?: string); constructor(options: DtStartOptions<DT>); /** * Creates a DtStart instance from a plain object representation. * * @param plain - Plain object with date/time and optional timezone * @returns A new DtStart instance * * @example * ```typescript * const plain = { * value: { year: 2024, month: 1, day: 15, hour: 9, minute: 0, second: 0, utc: false }, * tzid: "America/New_York" * }; * const dtstart = DtStart.fromPlain(plain); * ``` */ static fromPlain(plain: DtStartLike<DateTimeLike>): DtStart<DateTime<Time>>; static fromPlain(plain: DtStartLike<DateLike>): DtStart<DateTime<undefined>>; /** * Creates a new DtStart instance with a different timezone. * * @param tzid - Timezone identifier (e.g., "America/New_York") or undefined * @returns A new DtStart instance with the specified timezone * * @example * ```typescript * const dtstart = new DtStart(DateTime.local(2024, 1, 15, 9, 0, 0)); * const withTz = dtstart.setTzid("America/New_York"); * ``` */ setTzid(tzid: string | undefined): DtStart<DT>; /** * Creates a new DtStart instance with a different date/time value. * * @param datetime - The new date/time value * @returns A new DtStart instance with the specified value * * @example * ```typescript * const dtstart = new DtStart(DateTime.date(2024, 1, 15)); * const newStart = dtstart.setValue(DateTime.local(2024, 2, 1, 10, 0, 0)); * ``` */ setValue<NDT extends DateTime<Time> | DateTime<undefined>>(datetime: NDT): DtStart<NDT>; /** * Converts the DtStart instance to a plain object representation. * * @returns A plain object with date/time and optional timezone * * @example * ```typescript * const dtstart = new DtStart( * DateTime.local(2024, 1, 15, 9, 0, 0), * "America/New_York" * ); * const plain = dtstart.toPlain(); * // { * // value: { year: 2024, month: 1, day: 15, hour: 9, minute: 0, second: 0, utc: false }, * // tzid: "America/New_York" * // } * ``` */ toPlain(): DtStartLike<DT extends DateTime<Time> ? DateTimeLike : DateLike>; }