UNPKG

7.16 kBTypeScriptView Raw
1export interface DateIOFormats<TLibFormatToken = string> {
2 /** Localized full date @example "Jan 1, 2019" */
3 fullDate: TLibFormatToken;
4 /** Partially localized full date with weekday, useful for text-to-speech accessibility @example "Tuesday, January 1, 2019" */
5 fullDateWithWeekday: TLibFormatToken;
6 /** Date format string with month and day of month @example "1 January" */
7 normalDate: TLibFormatToken;
8 /** Date format string with weekday, month and day of month @example "Wed, Jan 1" */
9 normalDateWithWeekday: TLibFormatToken;
10 /** Shorter day format @example "Jan 1" */
11 shortDate: TLibFormatToken;
12 /** Year format string @example "2019" */
13 year: TLibFormatToken;
14 /** Month format string @example "January" */
15 month: TLibFormatToken;
16 /** Short month format string @example "Jan" */
17 monthShort: TLibFormatToken;
18 /** Month with year format string @example "January 2018" */
19 monthAndYear: TLibFormatToken;
20 /** Month with date format string @example "January 1" */
21 monthAndDate: TLibFormatToken;
22 /** Weekday format string @example "Wednesday" */
23 weekday: TLibFormatToken;
24 /** Short weekday format string @example "Wed" */
25 weekdayShort: TLibFormatToken;
26 /** Day format string @example "1" */
27 dayOfMonth: TLibFormatToken;
28 /** Hours format string @example "11" */
29 hours12h: TLibFormatToken;
30 /** Hours format string @example "23" */
31 hours24h: TLibFormatToken;
32 /** Minutes format string @example "44" */
33 minutes: TLibFormatToken;
34 /** Seconds format string @example "00" */
35 seconds: TLibFormatToken;
36 /** Full time localized format string @example "11:44 PM" for US, "23:44" for Europe */
37 fullTime: TLibFormatToken;
38 /** Not localized full time format string @example "11:44 PM" */
39 fullTime12h: TLibFormatToken;
40 /** Not localized full time format string @example "23:44" */
41 fullTime24h: TLibFormatToken;
42 /** Date & time format string with localized time @example "Jan 1, 2018 11:44 PM" */
43 fullDateTime: TLibFormatToken;
44 /** Not localized date & Time format 12h @example "Jan 1, 2018 11:44 PM" */
45 fullDateTime12h: TLibFormatToken;
46 /** Not localized date & Time format 24h @example "Jan 1, 2018 23:44" */
47 fullDateTime24h: TLibFormatToken;
48 /** Localized keyboard input friendly date format @example "02/13/2020 */
49 keyboardDate: TLibFormatToken;
50 /** Localized keyboard input friendly date/time format @example "02/13/2020 23:44" */
51 keyboardDateTime: TLibFormatToken;
52 /** Partially localized keyboard input friendly date/time 12h format @example "02/13/2020 11:44 PM" */
53 keyboardDateTime12h: TLibFormatToken;
54 /** Partially localized keyboard input friendly date/time 24h format @example "02/13/2020 23:44" */
55 keyboardDateTime24h: TLibFormatToken;
56}
57
58export type Unit =
59 | "years"
60 | "quarters"
61 | "months"
62 | "weeks"
63 | "days"
64 | "hours"
65 | "minutes"
66 | "seconds"
67 | "milliseconds";
68
69type ConstructorOptions<TLocale> = {
70 formats?: Partial<DateIOFormats>;
71 locale?: TLocale;
72 instance?: any;
73};
74
75export interface IUtils<TDate, TLocale> {
76 formats: DateIOFormats<any>;
77 locale?: TLocale;
78 moment?: any;
79 dayjs?: any;
80 /** Name of the library that is used right now */
81 lib: string;
82
83 // Constructor type
84 // new (options?: {
85 // formats?: Partial<DateIOFormats>;
86 // locale?: TLocale;
87 // instance?: any;
88 // }): IUtils<TDate, TLocale>;
89
90 /**
91 * Creates a date object. Use `utils.date()` to create a new date object of the underlying library.`
92 * Supports some of the standard input sources like ISO strings so you can pass the string directly
93 * as `utils.date("2024-01-10T14:30:00Z"), and javascript `Date` objects `utils.date(new Date())`.
94 *
95 * if `null` is passed `null` will be returned.
96 */
97 date<
98 TArg extends unknown = undefined,
99 TResultingDate extends unknown = TArg extends null
100 ? null
101 : TArg extends undefined
102 ? TDate
103 : TDate | null
104 >(
105 value?: TArg
106 ): TResultingDate;
107 toJsDate(value: TDate): Date;
108 parseISO(isString: string): TDate;
109 toISO(value: TDate): string;
110 parse(value: string, format: string): TDate | null;
111
112 getCurrentLocaleCode(): string;
113 is12HourCycleInCurrentLocale(): boolean;
114 /**
115 * Returns user readable format (taking into account localized format tokens), useful to render helper text for input (e.g. placeholder).
116 * If helper can not be created and **for luxon** always returns empty string.
117 * */
118 getFormatHelperText(format: string): string;
119
120 isNull(value: TDate | null): boolean;
121 isValid(value: any): boolean;
122 getDiff(value: TDate, comparing: TDate | string, unit?: Unit): number;
123 isEqual(value: any, comparing: any): boolean;
124
125 isSameDay(value: TDate, comparing: TDate): boolean;
126 isSameMonth(value: TDate, comparing: TDate): boolean;
127 isSameYear(value: TDate, comparing: TDate): boolean;
128 isSameHour(value: TDate, comparing: TDate): boolean;
129
130 isAfter(value: TDate, comparing: TDate): boolean;
131 isAfterDay(value: TDate, comparing: TDate): boolean;
132 isAfterMonth(value: TDate, comparing: TDate): boolean;
133 isAfterYear(value: TDate, comparing: TDate): boolean;
134
135 isBefore(value: TDate, comparing: TDate): boolean;
136 isBeforeDay(value: TDate, comparing: TDate): boolean;
137 isBeforeMonth(value: TDate, comparing: TDate): boolean;
138 isBeforeYear(value: TDate, comparing: TDate): boolean;
139
140 isWithinRange(value: TDate, range: [TDate, TDate]): boolean;
141
142 startOfYear(value: TDate): TDate;
143 endOfYear(value: TDate): TDate;
144 startOfMonth(value: TDate): TDate;
145 endOfMonth(value: TDate): TDate;
146 startOfWeek(value: TDate): TDate;
147 endOfWeek(value: TDate): TDate;
148
149 addSeconds(value: TDate, count: number): TDate;
150 addMinutes(value: TDate, count: number): TDate;
151 addHours(value: TDate, count: number): TDate;
152 addDays(value: TDate, count: number): TDate;
153 addWeeks(value: TDate, count: number): TDate;
154 addMonths(value: TDate, count: number): TDate;
155 addYears(value: TDate, count: number): TDate;
156
157 startOfDay(value: TDate): TDate;
158 endOfDay(value: TDate): TDate;
159
160 format(value: TDate, formatKey: keyof DateIOFormats): string;
161 formatByString(value: TDate, formatString: string): string;
162 formatNumber(numberToFormat: string): string;
163
164 getHours(value: TDate): number;
165 setHours(value: TDate, count: number): TDate;
166
167 getMinutes(value: TDate): number;
168 setMinutes(value: TDate, count: number): TDate;
169
170 getSeconds(value: TDate): number;
171 setSeconds(value: TDate, count: number): TDate;
172
173 getDate(value: TDate): number;
174 setDate(value: TDate, count: number): TDate;
175
176 getWeek(value: TDate): number;
177 getMonth(value: TDate): number;
178 getDaysInMonth(value: TDate): number;
179 setMonth(value: TDate, count: number): TDate;
180 getNextMonth(value: TDate): TDate;
181 getPreviousMonth(value: TDate): TDate;
182
183 getMonthArray(value: TDate): TDate[];
184
185 getYear(value: TDate): number;
186 setYear(value: TDate, count: number): TDate;
187
188 mergeDateAndTime(date: TDate, time: TDate): TDate;
189
190 getWeekdays(): string[];
191 getWeekArray(date: TDate): TDate[][];
192 getYearRange(start: TDate, end: TDate): TDate[];
193
194 /** Allow to customize displaying "am/pm" strings */
195 getMeridiemText(ampm: "am" | "pm"): string;
196}