UNPKG

9.57 kBTypeScriptView Raw
1import { EndOfWeekOptions, FormatOptions as DateFnsFormatOptions, StartOfWeekOptions, addDays, addMonths, addWeeks, addYears, differenceInCalendarDays, differenceInCalendarMonths, endOfISOWeek, endOfMonth, endOfWeek, endOfYear, format, getISOWeek, getWeek, isAfter, isBefore, isSameDay, isSameMonth, isSameYear, max, min, setMonth, setYear, startOfDay, startOfISOWeek, startOfMonth, startOfWeek, startOfYear } from "date-fns";
2import type { Locale } from "date-fns/locale";
3import { endOfBroadcastWeek } from "../helpers/endOfBroadcastWeek.js";
4import { startOfBroadcastWeek } from "../helpers/startOfBroadcastWeek.js";
5export type { Locale } from "date-fns/locale";
6export type { Month as DateFnsMonth } from "date-fns";
7/**
8 * @ignore
9 * @deprecated Use {@link DateLibOptions} instead.
10 */
11export type FormatOptions = DateLibOptions;
12/**
13 * @ignore
14 * @deprecated Use {@link DateLibOptions} instead.
15 */
16export type LabelOptions = DateLibOptions;
17/**
18 * The options for the `DateLib` class.
19 *
20 * Extends `date-fns` [format](https://date-fns.org/docs/format),
21 * [startOfWeek](https://date-fns.org/docs/startOfWeek) and
22 * [endOfWeek](https://date-fns.org/docs/endOfWeek) options.
23 *
24 * @since 9.2.0
25 */
26export interface DateLibOptions extends DateFnsFormatOptions, StartOfWeekOptions, EndOfWeekOptions {
27 /** A constructor for the `Date` object. */
28 Date?: typeof Date;
29 /** A locale to use for formatting dates. */
30 locale?: Locale;
31}
32/**
33 * A wrapper class around [date-fns](http://date-fns.org) sharing the same
34 * options. Methods of this class can be overridden using the
35 * {@link PropsBase.dateLib} prop.
36 *
37 * @since 9.2.0
38 * @example
39 * const dateLib = new DateLib({ locale: es });
40 * const newDate = dateLib.addDays(new Date(), 5);
41 */
42export declare class DateLib {
43 /** The options for the date library. */
44 readonly options: DateLibOptions;
45 /** Overrides for the date library functions. */
46 readonly overrides?: Partial<typeof DateLib.prototype>;
47 /**
48 * Creates an instance of DateLib.
49 *
50 * @param options The options for the date library.
51 * @param overrides Overrides for the date library functions.
52 */
53 constructor(options?: DateLibOptions, overrides?: Partial<typeof DateLib.prototype>);
54 /** Reference to the built-in Date constructor. */
55 Date: typeof Date;
56 /**
57 * Adds the specified number of days to the given date.
58 *
59 * @param date The date to add days to.
60 * @param amount The number of days to add.
61 * @returns The new date with the days added.
62 */
63 addDays: typeof addDays;
64 /**
65 * Adds the specified number of months to the given date.
66 *
67 * @param date The date to add months to.
68 * @param amount The number of months to add.
69 * @returns The new date with the months added.
70 */
71 addMonths: typeof addMonths;
72 /**
73 * Adds the specified number of weeks to the given date.
74 *
75 * @param date The date to add weeks to.
76 * @param amount The number of weeks to add.
77 * @returns The new date with the weeks added.
78 */
79 addWeeks: typeof addWeeks;
80 /**
81 * Adds the specified number of years to the given date.
82 *
83 * @param date The date to add years to.
84 * @param amount The number of years to add.
85 * @returns The new date with the years added.
86 */
87 addYears: typeof addYears;
88 /**
89 * Returns the number of calendar days between the given dates.
90 *
91 * @param dateLeft The later date.
92 * @param dateRight The earlier date.
93 * @returns The number of calendar days between the dates.
94 */
95 differenceInCalendarDays: typeof differenceInCalendarDays;
96 /**
97 * Returns the number of calendar months between the given dates.
98 *
99 * @param dateLeft The later date.
100 * @param dateRight The earlier date.
101 * @returns The number of calendar months between the dates.
102 */
103 differenceInCalendarMonths: typeof differenceInCalendarMonths;
104 /**
105 * Returns the end of the broadcast week for the given date.
106 *
107 * @param date The original date.
108 * @returns The end of the broadcast week.
109 */
110 endOfBroadcastWeek: typeof endOfBroadcastWeek;
111 /**
112 * Returns the end of the ISO week for the given date.
113 *
114 * @param date The original date.
115 * @returns The end of the ISO week.
116 */
117 endOfISOWeek: typeof endOfISOWeek;
118 /**
119 * Returns the end of the month for the given date.
120 *
121 * @param date The original date.
122 * @returns The end of the month.
123 */
124 endOfMonth: typeof endOfMonth;
125 /**
126 * Returns the end of the week for the given date.
127 *
128 * @param date The original date.
129 * @returns The end of the week.
130 */
131 endOfWeek: typeof endOfWeek;
132 /**
133 * Returns the end of the year for the given date.
134 *
135 * @param date The original date.
136 * @returns The end of the year.
137 */
138 endOfYear: typeof endOfYear;
139 /**
140 * Formats the given date using the specified format string.
141 *
142 * @param date The date to format.
143 * @param formatStr The format string.
144 * @returns The formatted date string.
145 */
146 format: typeof format;
147 /**
148 * Returns the ISO week number for the given date.
149 *
150 * @param date The date to get the ISO week number for.
151 * @returns The ISO week number.
152 */
153 getISOWeek: typeof getISOWeek;
154 /**
155 * Returns the local week number for the given date.
156 *
157 * @param date The date to get the week number for.
158 * @returns The week number.
159 */
160 getWeek: typeof getWeek;
161 /**
162 * Checks if the first date is after the second date.
163 *
164 * @param date The date to compare.
165 * @param dateToCompare The date to compare with.
166 * @returns True if the first date is after the second date.
167 */
168 isAfter: typeof isAfter;
169 /**
170 * Checks if the first date is before the second date.
171 *
172 * @param date The date to compare.
173 * @param dateToCompare The date to compare with.
174 * @returns True if the first date is before the second date.
175 */
176 isBefore: typeof isBefore;
177 /**
178 * Checks if the given value is a Date object.
179 *
180 * @param value The value to check.
181 * @returns True if the value is a Date object.
182 */
183 isDate: (value: unknown) => value is Date;
184 /**
185 * Checks if the given dates are on the same day.
186 *
187 * @param dateLeft The first date to compare.
188 * @param dateRight The second date to compare.
189 * @returns True if the dates are on the same day.
190 */
191 isSameDay: typeof isSameDay;
192 /**
193 * Checks if the given dates are in the same month.
194 *
195 * @param dateLeft The first date to compare.
196 * @param dateRight The second date to compare.
197 * @returns True if the dates are in the same month.
198 */
199 isSameMonth: typeof isSameMonth;
200 /**
201 * Checks if the given dates are in the same year.
202 *
203 * @param dateLeft The first date to compare.
204 * @param dateRight The second date to compare.
205 * @returns True if the dates are in the same year.
206 */
207 isSameYear: typeof isSameYear;
208 /**
209 * Returns the latest date in the given array of dates.
210 *
211 * @param dates The array of dates to compare.
212 * @returns The latest date.
213 */
214 max: typeof max;
215 /**
216 * Returns the earliest date in the given array of dates.
217 *
218 * @param dates The array of dates to compare.
219 * @returns The earliest date.
220 */
221 min: typeof min;
222 /**
223 * Sets the month of the given date.
224 *
225 * @param date The date to set the month on.
226 * @param month The month to set (0-11).
227 * @returns The new date with the month set.
228 */
229 setMonth: typeof setMonth;
230 /**
231 * Sets the year of the given date.
232 *
233 * @param date The date to set the year on.
234 * @param year The year to set.
235 * @returns The new date with the year set.
236 */
237 setYear: typeof setYear;
238 /**
239 * Returns the start of the broadcast week for the given date.
240 *
241 * @param date The original date.
242 * @returns The start of the broadcast week.
243 */
244 startOfBroadcastWeek: typeof startOfBroadcastWeek;
245 /**
246 * Returns the start of the day for the given date.
247 *
248 * @param date The original date.
249 * @returns The start of the day.
250 */
251 startOfDay: typeof startOfDay;
252 /**
253 * Returns the start of the ISO week for the given date.
254 *
255 * @param date The original date.
256 * @returns The start of the ISO week.
257 */
258 startOfISOWeek: typeof startOfISOWeek;
259 /**
260 * Returns the start of the month for the given date.
261 *
262 * @param date The original date.
263 * @returns The start of the month.
264 */
265 startOfMonth: typeof startOfMonth;
266 /**
267 * Returns the start of the week for the given date.
268 *
269 * @param date The original date.
270 * @returns The start of the week.
271 */
272 startOfWeek: typeof startOfWeek;
273 /**
274 * Returns the start of the year for the given date.
275 *
276 * @param date The original date.
277 * @returns The start of the year.
278 */
279 startOfYear: typeof startOfYear;
280}
281/** The default locale (English). */
282export { enUS as defaultLocale } from "date-fns/locale/en-US";
283/**
284 * The default date library with English locale.
285 *
286 * @since 9.2.0
287 */
288export declare const defaultDateLib: DateLib;
289/**
290 * @ignore
291 * @deprecated Use `defaultDateLib`.
292 */
293export declare const dateLib: DateLib;