UNPKG

6.26 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 /** Returns user readable format (taking into account localized format tokens), useful to render helper text for input (e.g. placeholder). For luxon always returns empty string. */
90 getFormatHelperText(format: string): string;
91
92 isNull(value: TDate | null): boolean;
93 isValid(value: any): boolean;
94 getDiff(value: TDate, comparing: TDate | string, unit?: Unit): number;
95 isEqual(value: any, comparing: any): boolean;
96
97 isSameDay(value: TDate, comparing: TDate): boolean;
98 isSameMonth(value: TDate, comparing: TDate): boolean;
99 isSameYear(value: TDate, comparing: TDate): boolean;
100 isSameHour(value: TDate, comparing: TDate): boolean;
101
102 isAfter(value: TDate, comparing: TDate): boolean;
103 isAfterDay(value: TDate, comparing: TDate): boolean;
104 isAfterYear(value: TDate, comparing: TDate): boolean;
105
106 isBeforeDay(value: TDate, comparing: TDate): boolean;
107 isBeforeYear(value: TDate, comparing: TDate): boolean;
108 isBefore(value: TDate, comparing: TDate): boolean;
109
110 isWithinRange(value: TDate, range: [TDate, TDate]): boolean;
111
112 startOfYear(value: TDate): TDate;
113 endOfYear(value: TDate): TDate;
114 startOfMonth(value: TDate): TDate;
115 endOfMonth(value: TDate): TDate;
116 startOfWeek(value: TDate): TDate;
117 endOfWeek(value: TDate): TDate;
118
119 addSeconds(value: TDate, count: number): TDate;
120 addMinutes(value: TDate, count: number): TDate;
121 addHours(value: TDate, count: number): TDate;
122 addDays(value: TDate, count: number): TDate;
123 addWeeks(value: TDate, count: number): TDate;
124 addMonths(value: TDate, count: number): TDate;
125 addYears(value: TDate, count: number): TDate;
126
127 startOfDay(value: TDate): TDate;
128 endOfDay(value: TDate): TDate;
129
130 format(value: TDate, formatKey: keyof DateIOFormats): string;
131 formatByString(value: TDate, formatString: string): string;
132 formatNumber(numberToFormat: string): string;
133
134 getHours(value: TDate): number;
135 setHours(value: TDate, count: number): TDate;
136
137 getMinutes(value: TDate): number;
138 setMinutes(value: TDate, count: number): TDate;
139
140 getSeconds(value: TDate): number;
141 setSeconds(value: TDate, count: number): TDate;
142
143 getDate(value: TDate): number;
144 setDate(value: TDate, count: number): TDate;
145
146 getMonth(value: TDate): number;
147 getDaysInMonth(value: TDate): number;
148 setMonth(value: TDate, count: number): TDate;
149 getNextMonth(value: TDate): TDate;
150 getPreviousMonth(value: TDate): TDate;
151
152 getMonthArray(value: TDate): TDate[];
153
154 getYear(value: TDate): number;
155 setYear(value: TDate, count: number): TDate;
156
157 mergeDateAndTime(date: TDate, time: TDate): TDate;
158
159 getWeekdays(): string[];
160 getWeekArray(date: TDate): TDate[][];
161 getYearRange(start: TDate, end: TDate): TDate[];
162
163 /** Allow to customize displaying "am/pm" strings */
164 getMeridiemText(ampm: "am" | "pm"): string;
165}