UNPKG

rrule-rust

Version:

RRule implementation for browsers and Node.js written in Rust

77 lines (76 loc) 2.16 kB
import { DateTime, } from './datetime'; /** * 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 class DtStart { constructor(valueOrOptions, tzid) { if ('value' in valueOrOptions) { this.value = valueOrOptions.value; this.tzid = valueOrOptions.tzid; } else { this.value = valueOrOptions; this.tzid = tzid; } } static fromPlain(plain) { return new this({ value: DateTime.fromPlain(plain.value), tzid: plain.tzid, }); } /** * 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) { return new DtStart(this.value, tzid); } /** * 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(datetime) { return new DtStart(datetime, this.tzid); } toPlain() { return { value: this.value.toPlain(), tzid: this.tzid, }; } }