@rschedule/rschedule
Version:
A typescript library for working with recurring dates and events.
129 lines • 6.08 kB
TypeScript
export declare const WEEKDAYS: ReadonlyArray<'SU' | 'MO' | 'TU' | 'WE' | 'TH' | 'FR' | 'SA'>;
export declare const MILLISECONDS_IN_SECOND = 1000;
export declare const MILLISECONDS_IN_MINUTE: number;
export declare const MILLISECONDS_IN_HOUR: number;
export declare const MILLISECONDS_IN_DAY: number;
export declare const MILLISECONDS_IN_WEEK: number;
export interface IDateAdapter<D = unknown> {
/** Returns the date object this DateAdapter is wrapping */
readonly date: D;
readonly timezone: string | null;
readonly duration: number | undefined;
/**
* This property contains an ordered array of the generator objects
* responsible for producing this IDateAdapter.
*
* - If this IDateAdapter was produced by a `Rule` object, this array
* will just contain the `Rule` object.
* - If this IDateAdapter was produced by a `Schedule` object, this
* array will contain the `Schedule` object as well as the `Rule`
* or `Dates` object which generated it.
* - If this IDateAdapter was produced by a `Calendar` object, this
* array will contain, at minimum, the `Calendar`, `Schedule`, and
* `Rule`/`Dates` objects which generated it.
*/
readonly generators: unknown[];
valueOf(): number;
toISOString(): string;
toDateTime(): DateTime;
toJSON(): IDateAdapter.JSON;
assertIsValid(): boolean;
}
export declare namespace IDateAdapter {
type Weekday = 'SU' | 'MO' | 'TU' | 'WE' | 'TH' | 'FR' | 'SA';
type TimeUnit = 'year' | 'month' | 'day' | 'hour' | 'minute' | 'second' | 'millisecond';
interface JSON {
timezone: string | null;
duration?: number;
year: number;
month: number;
day: number;
hour: number;
minute: number;
second: number;
millisecond: number;
}
type Year = number;
type YearDay = number;
type Month = 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12;
type Day = 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31;
type Hour = 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23;
type Minute = 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59;
type Second = Minute;
type Millisecond = number;
}
export declare class InvalidDateTimeError extends Error {
}
declare const DATETIME_ID: unique symbol;
export declare class DateTime implements IDateAdapter<unknown> {
/**
* Similar to `Array.isArray()`, `isInstance()` provides a surefire method
* of determining if an object is a `DateTime` by checking against the
* global symbol registry.
*/
static isInstance(object: any): object is DateTime;
static fromJSON(json: IDateAdapter.JSON): DateTime;
static fromDateAdapter(adapter: IDateAdapter): DateTime;
readonly date: Date;
/**
* This property contains an ordered array of the generator objects
* responsible for producing this DateAdapter.
*
* - If this DateAdapter was produced by a `Rule` object, this array
* will just contain the `Rule` object.
* - If this DateAdapter was produced by a `Schedule` object, this
* array will contain the `Schedule` object as well as the `Rule`
* or `Dates` object which generated it.
* - If this DateAdapter was produced by a `Calendar` object, this
* array will contain, at minimum, the `Calendar`, `Schedule`, and
* `Rule`/`Dates` objects which generated it.
*/
readonly generators: unknown[];
readonly [DATETIME_ID] = true;
readonly timezone: string | null;
readonly duration: number | undefined;
private _end;
private constructor();
/**
* Returns `undefined` if `this.duration` is falsey. Else returns
* the `end` date.
*/
readonly end: DateTime | undefined;
isEqual(object?: DateTime): boolean;
isBefore(object: DateTime): boolean;
isBeforeOrEqual(object: DateTime): boolean;
isAfter(object: DateTime): boolean;
isAfterOrEqual(object: DateTime): boolean;
isOccurring(object: DateTime): boolean;
add(amount: number, unit: IDateAdapter.TimeUnit | 'week'): DateTime;
subtract(amount: number, unit: IDateAdapter.TimeUnit | 'week'): DateTime;
get(unit: 'year'): IDateAdapter.Year;
get(unit: 'yearday'): IDateAdapter.YearDay;
get(unit: 'month'): IDateAdapter.Month;
get(unit: 'weekday'): IDateAdapter.Weekday;
get(unit: 'day'): IDateAdapter.Day;
get(unit: 'hour'): IDateAdapter.Hour;
get(unit: 'minute'): IDateAdapter.Minute;
get(unit: 'second'): IDateAdapter.Second;
get(unit: 'millisecond'): IDateAdapter.Millisecond;
set(unit: IDateAdapter.TimeUnit | 'duration', value: number): DateTime;
granularity(granularity: IDateAdapter.TimeUnit | 'week', opt?: {
weekStart?: IDateAdapter.Weekday;
}): DateTime;
endGranularity(granularity: IDateAdapter.TimeUnit | 'week', opt?: {
weekStart?: IDateAdapter.Weekday;
}): DateTime;
toISOString(): string;
toDateTime(): this;
toJSON(): IDateAdapter.JSON;
valueOf(): number;
assertIsValid(): boolean;
private forkDateTime;
}
export declare function dateTimeSortComparer(a: DateTime, b: DateTime): 0 | 1 | -1;
export declare function uniqDateTimes(dates: DateTime[]): DateTime[];
export declare function orderedWeekdays(wkst?: IDateAdapter.Weekday): ("SU" | "MO" | "TU" | "WE" | "TH" | "FR" | "SA")[];
export declare function isLeapYear(year: number): boolean;
export declare function getDaysInYear(year: number): 366 | 365;
export {};
//# sourceMappingURL=date-time.d.ts.map