UNPKG

6.43 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
69export interface ExtendableDateType {}
70
71export interface IUtils<TDate extends ExtendableDateType> {
72 formats: DateIOFormats<any>;
73 locale?: any;
74 moment?: any;
75 dayjs?: any;
76 /** Name of the library that is used right now */
77 lib: string;
78
79 // constructor (options?: { formats?: DateIOFormats, locale?: any, instance?: any });
80
81 date(value?: any): TDate | null;
82 toJsDate(value: TDate): Date;
83 parseISO(isString: string): TDate;
84 toISO(value: TDate): string;
85 parse(value: string, format: string): TDate | null;
86
87 getCurrentLocaleCode(): string;
88 is12HourCycleInCurrentLocale(): boolean;
89 /**
90 * Returns user readable format (taking into account localized format tokens), useful to render helper text for input (e.g. placeholder).
91 * If helper can not be created and **for luxon** always returns empty string.
92 * */
93 getFormatHelperText(format: string): string;
94
95 isNull(value: TDate | null): boolean;
96 isValid(value: any): boolean;
97 getDiff(value: TDate, comparing: TDate | string, unit?: Unit): number;
98 isEqual(value: any, comparing: any): boolean;
99
100 isSameDay(value: TDate, comparing: TDate): boolean;
101 isSameMonth(value: TDate, comparing: TDate): boolean;
102 isSameYear(value: TDate, comparing: TDate): boolean;
103 isSameHour(value: TDate, comparing: TDate): boolean;
104
105 isAfter(value: TDate, comparing: TDate): boolean;
106 isAfterDay(value: TDate, comparing: TDate): boolean;
107 isAfterMonth(value: TDate, comparing: TDate): boolean;
108 isAfterYear(value: TDate, comparing: TDate): boolean;
109
110 isBefore(value: TDate, comparing: TDate): boolean;
111 isBeforeDay(value: TDate, comparing: TDate): boolean;
112 isBeforeMonth(value: TDate, comparing: TDate): boolean;
113 isBeforeYear(value: TDate, comparing: TDate): boolean;
114
115 isWithinRange(value: TDate, range: [TDate, TDate]): boolean;
116
117 startOfYear(value: TDate): TDate;
118 endOfYear(value: TDate): TDate;
119 startOfMonth(value: TDate): TDate;
120 endOfMonth(value: TDate): TDate;
121 startOfWeek(value: TDate): TDate;
122 endOfWeek(value: TDate): TDate;
123
124 addSeconds(value: TDate, count: number): TDate;
125 addMinutes(value: TDate, count: number): TDate;
126 addHours(value: TDate, count: number): TDate;
127 addDays(value: TDate, count: number): TDate;
128 addWeeks(value: TDate, count: number): TDate;
129 addMonths(value: TDate, count: number): TDate;
130 addYears(value: TDate, count: number): TDate;
131
132 startOfDay(value: TDate): TDate;
133 endOfDay(value: TDate): TDate;
134
135 format(value: TDate, formatKey: keyof DateIOFormats): string;
136 formatByString(value: TDate, formatString: string): string;
137 formatNumber(numberToFormat: string): string;
138
139 getHours(value: TDate): number;
140 setHours(value: TDate, count: number): TDate;
141
142 getMinutes(value: TDate): number;
143 setMinutes(value: TDate, count: number): TDate;
144
145 getSeconds(value: TDate): number;
146 setSeconds(value: TDate, count: number): TDate;
147
148 getDate(value: TDate): number;
149 setDate(value: TDate, count: number): TDate;
150
151 getMonth(value: TDate): number;
152 getDaysInMonth(value: TDate): number;
153 setMonth(value: TDate, count: number): TDate;
154 getNextMonth(value: TDate): TDate;
155 getPreviousMonth(value: TDate): TDate;
156
157 getMonthArray(value: TDate): TDate[];
158
159 getYear(value: TDate): number;
160 setYear(value: TDate, count: number): TDate;
161
162 mergeDateAndTime(date: TDate, time: TDate): TDate;
163
164 getWeekdays(): string[];
165 getWeekArray(date: TDate): TDate[][];
166 getYearRange(start: TDate, end: TDate): TDate[];
167
168 /** Allow to customize displaying "am/pm" strings */
169 getMeridiemText(ampm: "am" | "pm"): string;
170}