react-day-picker 9.6.4 → 9.6.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/classes/DateLib.d.ts +36 -33
- package/dist/cjs/classes/DateLib.js +100 -51
- package/dist/cjs/classes/DateLib.js.map +1 -1
- package/dist/cjs/helpers/calculateFocusTarget.js +28 -20
- package/dist/cjs/helpers/calculateFocusTarget.js.map +1 -1
- package/dist/esm/classes/DateLib.d.ts +36 -33
- package/dist/esm/classes/DateLib.js +100 -51
- package/dist/esm/classes/DateLib.js.map +1 -1
- package/dist/esm/helpers/calculateFocusTarget.js +28 -20
- package/dist/esm/helpers/calculateFocusTarget.js.map +1 -1
- package/package.json +1 -1
- package/src/classes/DateLib.ts +150 -112
- package/src/helpers/calculateFocusTarget.test.ts +167 -0
- package/src/helpers/calculateFocusTarget.ts +39 -24
|
@@ -1,5 +1,8 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { addDays, addMonths, addWeeks, addYears, differenceInCalendarDays, differenceInCalendarMonths, eachMonthOfInterval, endOfISOWeek, endOfMonth, endOfWeek, endOfYear, format, getISOWeek, getMonth, getWeek, getYear, isAfter, isBefore, isSameDay, isSameMonth, isSameYear, max, min, setMonth, setYear, startOfDay, startOfISOWeek, startOfMonth, startOfWeek, startOfYear } from "date-fns";
|
|
2
|
+
import type { EndOfWeekOptions, StartOfWeekOptions, FormatOptions as DateFnsFormatOptions } from "date-fns";
|
|
2
3
|
import type { Locale } from "date-fns/locale";
|
|
4
|
+
import { endOfBroadcastWeek } from "../helpers/endOfBroadcastWeek.js";
|
|
5
|
+
import { startOfBroadcastWeek } from "../helpers/startOfBroadcastWeek.js";
|
|
3
6
|
import { Numerals } from "../types/shared.js";
|
|
4
7
|
export type { Locale } from "date-fns/locale";
|
|
5
8
|
export type { Month as DateFnsMonth } from "date-fns";
|
|
@@ -111,7 +114,7 @@ export declare class DateLib {
|
|
|
111
114
|
* @param amount The number of days to add.
|
|
112
115
|
* @returns The new date with the days added.
|
|
113
116
|
*/
|
|
114
|
-
addDays:
|
|
117
|
+
addDays: typeof addDays;
|
|
115
118
|
/**
|
|
116
119
|
* Adds the specified number of months to the given date.
|
|
117
120
|
*
|
|
@@ -119,7 +122,7 @@ export declare class DateLib {
|
|
|
119
122
|
* @param amount The number of months to add.
|
|
120
123
|
* @returns The new date with the months added.
|
|
121
124
|
*/
|
|
122
|
-
addMonths:
|
|
125
|
+
addMonths: typeof addMonths;
|
|
123
126
|
/**
|
|
124
127
|
* Adds the specified number of weeks to the given date.
|
|
125
128
|
*
|
|
@@ -127,7 +130,7 @@ export declare class DateLib {
|
|
|
127
130
|
* @param amount The number of weeks to add.
|
|
128
131
|
* @returns The new date with the weeks added.
|
|
129
132
|
*/
|
|
130
|
-
addWeeks:
|
|
133
|
+
addWeeks: typeof addWeeks;
|
|
131
134
|
/**
|
|
132
135
|
* Adds the specified number of years to the given date.
|
|
133
136
|
*
|
|
@@ -135,7 +138,7 @@ export declare class DateLib {
|
|
|
135
138
|
* @param amount The number of years to add.
|
|
136
139
|
* @returns The new date with the years added.
|
|
137
140
|
*/
|
|
138
|
-
addYears:
|
|
141
|
+
addYears: typeof addYears;
|
|
139
142
|
/**
|
|
140
143
|
* Returns the number of calendar days between the given dates.
|
|
141
144
|
*
|
|
@@ -143,7 +146,7 @@ export declare class DateLib {
|
|
|
143
146
|
* @param dateRight The earlier date.
|
|
144
147
|
* @returns The number of calendar days between the dates.
|
|
145
148
|
*/
|
|
146
|
-
differenceInCalendarDays:
|
|
149
|
+
differenceInCalendarDays: typeof differenceInCalendarDays;
|
|
147
150
|
/**
|
|
148
151
|
* Returns the number of calendar months between the given dates.
|
|
149
152
|
*
|
|
@@ -151,48 +154,48 @@ export declare class DateLib {
|
|
|
151
154
|
* @param dateRight The earlier date.
|
|
152
155
|
* @returns The number of calendar months between the dates.
|
|
153
156
|
*/
|
|
154
|
-
differenceInCalendarMonths:
|
|
157
|
+
differenceInCalendarMonths: typeof differenceInCalendarMonths;
|
|
155
158
|
/**
|
|
156
159
|
* Returns the months between the given dates.
|
|
157
160
|
*
|
|
158
161
|
* @param interval The interval to get the months for.
|
|
159
162
|
*/
|
|
160
|
-
eachMonthOfInterval:
|
|
163
|
+
eachMonthOfInterval: typeof eachMonthOfInterval;
|
|
161
164
|
/**
|
|
162
165
|
* Returns the end of the broadcast week for the given date.
|
|
163
166
|
*
|
|
164
167
|
* @param date The original date.
|
|
165
168
|
* @returns The end of the broadcast week.
|
|
166
169
|
*/
|
|
167
|
-
endOfBroadcastWeek:
|
|
170
|
+
endOfBroadcastWeek: typeof endOfBroadcastWeek;
|
|
168
171
|
/**
|
|
169
172
|
* Returns the end of the ISO week for the given date.
|
|
170
173
|
*
|
|
171
174
|
* @param date The original date.
|
|
172
175
|
* @returns The end of the ISO week.
|
|
173
176
|
*/
|
|
174
|
-
endOfISOWeek:
|
|
177
|
+
endOfISOWeek: typeof endOfISOWeek;
|
|
175
178
|
/**
|
|
176
179
|
* Returns the end of the month for the given date.
|
|
177
180
|
*
|
|
178
181
|
* @param date The original date.
|
|
179
182
|
* @returns The end of the month.
|
|
180
183
|
*/
|
|
181
|
-
endOfMonth:
|
|
184
|
+
endOfMonth: typeof endOfMonth;
|
|
182
185
|
/**
|
|
183
186
|
* Returns the end of the week for the given date.
|
|
184
187
|
*
|
|
185
188
|
* @param date The original date.
|
|
186
189
|
* @returns The end of the week.
|
|
187
190
|
*/
|
|
188
|
-
endOfWeek:
|
|
191
|
+
endOfWeek: typeof endOfWeek;
|
|
189
192
|
/**
|
|
190
193
|
* Returns the end of the year for the given date.
|
|
191
194
|
*
|
|
192
195
|
* @param date The original date.
|
|
193
196
|
* @returns The end of the year.
|
|
194
197
|
*/
|
|
195
|
-
endOfYear:
|
|
198
|
+
endOfYear: typeof endOfYear;
|
|
196
199
|
/**
|
|
197
200
|
* Formats the given date using the specified format string.
|
|
198
201
|
*
|
|
@@ -200,35 +203,35 @@ export declare class DateLib {
|
|
|
200
203
|
* @param formatStr The format string.
|
|
201
204
|
* @returns The formatted date string.
|
|
202
205
|
*/
|
|
203
|
-
format:
|
|
206
|
+
format: typeof format;
|
|
204
207
|
/**
|
|
205
208
|
* Returns the ISO week number for the given date.
|
|
206
209
|
*
|
|
207
210
|
* @param date The date to get the ISO week number for.
|
|
208
211
|
* @returns The ISO week number.
|
|
209
212
|
*/
|
|
210
|
-
getISOWeek:
|
|
213
|
+
getISOWeek: typeof getISOWeek;
|
|
211
214
|
/**
|
|
212
215
|
* Returns the month of the given date.
|
|
213
216
|
*
|
|
214
217
|
* @param date The date to get the month for.
|
|
215
218
|
* @returns The month.
|
|
216
219
|
*/
|
|
217
|
-
getMonth:
|
|
220
|
+
getMonth: typeof getMonth;
|
|
218
221
|
/**
|
|
219
222
|
* Returns the year of the given date.
|
|
220
223
|
*
|
|
221
224
|
* @param date The date to get the year for.
|
|
222
225
|
* @returns The year.
|
|
223
226
|
*/
|
|
224
|
-
getYear:
|
|
227
|
+
getYear: typeof getYear;
|
|
225
228
|
/**
|
|
226
229
|
* Returns the local week number for the given date.
|
|
227
230
|
*
|
|
228
231
|
* @param date The date to get the week number for.
|
|
229
232
|
* @returns The week number.
|
|
230
233
|
*/
|
|
231
|
-
getWeek:
|
|
234
|
+
getWeek: typeof getWeek;
|
|
232
235
|
/**
|
|
233
236
|
* Checks if the first date is after the second date.
|
|
234
237
|
*
|
|
@@ -236,7 +239,7 @@ export declare class DateLib {
|
|
|
236
239
|
* @param dateToCompare The date to compare with.
|
|
237
240
|
* @returns True if the first date is after the second date.
|
|
238
241
|
*/
|
|
239
|
-
isAfter:
|
|
242
|
+
isAfter: typeof isAfter;
|
|
240
243
|
/**
|
|
241
244
|
* Checks if the first date is before the second date.
|
|
242
245
|
*
|
|
@@ -244,7 +247,7 @@ export declare class DateLib {
|
|
|
244
247
|
* @param dateToCompare The date to compare with.
|
|
245
248
|
* @returns True if the first date is before the second date.
|
|
246
249
|
*/
|
|
247
|
-
isBefore:
|
|
250
|
+
isBefore: typeof isBefore;
|
|
248
251
|
/**
|
|
249
252
|
* Checks if the given value is a Date object.
|
|
250
253
|
*
|
|
@@ -259,7 +262,7 @@ export declare class DateLib {
|
|
|
259
262
|
* @param dateRight The second date to compare.
|
|
260
263
|
* @returns True if the dates are on the same day.
|
|
261
264
|
*/
|
|
262
|
-
isSameDay:
|
|
265
|
+
isSameDay: typeof isSameDay;
|
|
263
266
|
/**
|
|
264
267
|
* Checks if the given dates are in the same month.
|
|
265
268
|
*
|
|
@@ -267,7 +270,7 @@ export declare class DateLib {
|
|
|
267
270
|
* @param dateRight The second date to compare.
|
|
268
271
|
* @returns True if the dates are in the same month.
|
|
269
272
|
*/
|
|
270
|
-
isSameMonth:
|
|
273
|
+
isSameMonth: typeof isSameMonth;
|
|
271
274
|
/**
|
|
272
275
|
* Checks if the given dates are in the same year.
|
|
273
276
|
*
|
|
@@ -275,21 +278,21 @@ export declare class DateLib {
|
|
|
275
278
|
* @param dateRight The second date to compare.
|
|
276
279
|
* @returns True if the dates are in the same year.
|
|
277
280
|
*/
|
|
278
|
-
isSameYear:
|
|
281
|
+
isSameYear: typeof isSameYear;
|
|
279
282
|
/**
|
|
280
283
|
* Returns the latest date in the given array of dates.
|
|
281
284
|
*
|
|
282
285
|
* @param dates The array of dates to compare.
|
|
283
286
|
* @returns The latest date.
|
|
284
287
|
*/
|
|
285
|
-
max:
|
|
288
|
+
max: typeof max;
|
|
286
289
|
/**
|
|
287
290
|
* Returns the earliest date in the given array of dates.
|
|
288
291
|
*
|
|
289
292
|
* @param dates The array of dates to compare.
|
|
290
293
|
* @returns The earliest date.
|
|
291
294
|
*/
|
|
292
|
-
min:
|
|
295
|
+
min: typeof min;
|
|
293
296
|
/**
|
|
294
297
|
* Sets the month of the given date.
|
|
295
298
|
*
|
|
@@ -297,7 +300,7 @@ export declare class DateLib {
|
|
|
297
300
|
* @param month The month to set (0-11).
|
|
298
301
|
* @returns The new date with the month set.
|
|
299
302
|
*/
|
|
300
|
-
setMonth:
|
|
303
|
+
setMonth: typeof setMonth;
|
|
301
304
|
/**
|
|
302
305
|
* Sets the year of the given date.
|
|
303
306
|
*
|
|
@@ -305,49 +308,49 @@ export declare class DateLib {
|
|
|
305
308
|
* @param year The year to set.
|
|
306
309
|
* @returns The new date with the year set.
|
|
307
310
|
*/
|
|
308
|
-
setYear:
|
|
311
|
+
setYear: typeof setYear;
|
|
309
312
|
/**
|
|
310
313
|
* Returns the start of the broadcast week for the given date.
|
|
311
314
|
*
|
|
312
315
|
* @param date The original date.
|
|
313
316
|
* @returns The start of the broadcast week.
|
|
314
317
|
*/
|
|
315
|
-
startOfBroadcastWeek:
|
|
318
|
+
startOfBroadcastWeek: typeof startOfBroadcastWeek;
|
|
316
319
|
/**
|
|
317
320
|
* Returns the start of the day for the given date.
|
|
318
321
|
*
|
|
319
322
|
* @param date The original date.
|
|
320
323
|
* @returns The start of the day.
|
|
321
324
|
*/
|
|
322
|
-
startOfDay:
|
|
325
|
+
startOfDay: typeof startOfDay;
|
|
323
326
|
/**
|
|
324
327
|
* Returns the start of the ISO week for the given date.
|
|
325
328
|
*
|
|
326
329
|
* @param date The original date.
|
|
327
330
|
* @returns The start of the ISO week.
|
|
328
331
|
*/
|
|
329
|
-
startOfISOWeek:
|
|
332
|
+
startOfISOWeek: typeof startOfISOWeek;
|
|
330
333
|
/**
|
|
331
334
|
* Returns the start of the month for the given date.
|
|
332
335
|
*
|
|
333
336
|
* @param date The original date.
|
|
334
337
|
* @returns The start of the month.
|
|
335
338
|
*/
|
|
336
|
-
startOfMonth:
|
|
339
|
+
startOfMonth: typeof startOfMonth;
|
|
337
340
|
/**
|
|
338
341
|
* Returns the start of the week for the given date.
|
|
339
342
|
*
|
|
340
343
|
* @param date The original date.
|
|
341
344
|
* @returns The start of the week.
|
|
342
345
|
*/
|
|
343
|
-
startOfWeek:
|
|
346
|
+
startOfWeek: typeof startOfWeek;
|
|
344
347
|
/**
|
|
345
348
|
* Returns the start of the year for the given date.
|
|
346
349
|
*
|
|
347
350
|
* @param date The original date.
|
|
348
351
|
* @returns The start of the year.
|
|
349
352
|
*/
|
|
350
|
-
startOfYear:
|
|
353
|
+
startOfYear: typeof startOfYear;
|
|
351
354
|
}
|
|
352
355
|
/** The default locale (English). */
|
|
353
356
|
export { enUS as defaultLocale } from "date-fns/locale/en-US";
|
|
@@ -70,7 +70,9 @@ class DateLib {
|
|
|
70
70
|
* @returns The new date with the days added.
|
|
71
71
|
*/
|
|
72
72
|
this.addDays = (date, amount) => {
|
|
73
|
-
return this.overrides?.addDays
|
|
73
|
+
return this.overrides?.addDays
|
|
74
|
+
? this.overrides.addDays(date, amount)
|
|
75
|
+
: (0, date_fns_1.addDays)(date, amount);
|
|
74
76
|
};
|
|
75
77
|
/**
|
|
76
78
|
* Adds the specified number of months to the given date.
|
|
@@ -80,7 +82,9 @@ class DateLib {
|
|
|
80
82
|
* @returns The new date with the months added.
|
|
81
83
|
*/
|
|
82
84
|
this.addMonths = (date, amount) => {
|
|
83
|
-
return this.overrides?.addMonths
|
|
85
|
+
return this.overrides?.addMonths
|
|
86
|
+
? this.overrides.addMonths(date, amount)
|
|
87
|
+
: (0, date_fns_1.addMonths)(date, amount);
|
|
84
88
|
};
|
|
85
89
|
/**
|
|
86
90
|
* Adds the specified number of weeks to the given date.
|
|
@@ -90,7 +94,9 @@ class DateLib {
|
|
|
90
94
|
* @returns The new date with the weeks added.
|
|
91
95
|
*/
|
|
92
96
|
this.addWeeks = (date, amount) => {
|
|
93
|
-
return this.overrides?.addWeeks
|
|
97
|
+
return this.overrides?.addWeeks
|
|
98
|
+
? this.overrides.addWeeks(date, amount)
|
|
99
|
+
: (0, date_fns_1.addWeeks)(date, amount);
|
|
94
100
|
};
|
|
95
101
|
/**
|
|
96
102
|
* Adds the specified number of years to the given date.
|
|
@@ -100,7 +106,9 @@ class DateLib {
|
|
|
100
106
|
* @returns The new date with the years added.
|
|
101
107
|
*/
|
|
102
108
|
this.addYears = (date, amount) => {
|
|
103
|
-
return this.overrides?.addYears
|
|
109
|
+
return this.overrides?.addYears
|
|
110
|
+
? this.overrides.addYears(date, amount)
|
|
111
|
+
: (0, date_fns_1.addYears)(date, amount);
|
|
104
112
|
};
|
|
105
113
|
/**
|
|
106
114
|
* Returns the number of calendar days between the given dates.
|
|
@@ -110,8 +118,9 @@ class DateLib {
|
|
|
110
118
|
* @returns The number of calendar days between the dates.
|
|
111
119
|
*/
|
|
112
120
|
this.differenceInCalendarDays = (dateLeft, dateRight) => {
|
|
113
|
-
return
|
|
114
|
-
|
|
121
|
+
return this.overrides?.differenceInCalendarDays
|
|
122
|
+
? this.overrides.differenceInCalendarDays(dateLeft, dateRight)
|
|
123
|
+
: (0, date_fns_1.differenceInCalendarDays)(dateLeft, dateRight);
|
|
115
124
|
};
|
|
116
125
|
/**
|
|
117
126
|
* Returns the number of calendar months between the given dates.
|
|
@@ -121,8 +130,9 @@ class DateLib {
|
|
|
121
130
|
* @returns The number of calendar months between the dates.
|
|
122
131
|
*/
|
|
123
132
|
this.differenceInCalendarMonths = (dateLeft, dateRight) => {
|
|
124
|
-
return
|
|
125
|
-
|
|
133
|
+
return this.overrides?.differenceInCalendarMonths
|
|
134
|
+
? this.overrides.differenceInCalendarMonths(dateLeft, dateRight)
|
|
135
|
+
: (0, date_fns_1.differenceInCalendarMonths)(dateLeft, dateRight);
|
|
126
136
|
};
|
|
127
137
|
/**
|
|
128
138
|
* Returns the months between the given dates.
|
|
@@ -130,8 +140,9 @@ class DateLib {
|
|
|
130
140
|
* @param interval The interval to get the months for.
|
|
131
141
|
*/
|
|
132
142
|
this.eachMonthOfInterval = (interval) => {
|
|
133
|
-
return
|
|
134
|
-
|
|
143
|
+
return this.overrides?.eachMonthOfInterval
|
|
144
|
+
? this.overrides.eachMonthOfInterval(interval)
|
|
145
|
+
: (0, date_fns_1.eachMonthOfInterval)(interval);
|
|
135
146
|
};
|
|
136
147
|
/**
|
|
137
148
|
* Returns the end of the broadcast week for the given date.
|
|
@@ -139,9 +150,10 @@ class DateLib {
|
|
|
139
150
|
* @param date The original date.
|
|
140
151
|
* @returns The end of the broadcast week.
|
|
141
152
|
*/
|
|
142
|
-
this.endOfBroadcastWeek = (date
|
|
143
|
-
return
|
|
144
|
-
|
|
153
|
+
this.endOfBroadcastWeek = (date) => {
|
|
154
|
+
return this.overrides?.endOfBroadcastWeek
|
|
155
|
+
? this.overrides.endOfBroadcastWeek(date, this)
|
|
156
|
+
: (0, endOfBroadcastWeek_js_1.endOfBroadcastWeek)(date, this);
|
|
145
157
|
};
|
|
146
158
|
/**
|
|
147
159
|
* Returns the end of the ISO week for the given date.
|
|
@@ -150,7 +162,9 @@ class DateLib {
|
|
|
150
162
|
* @returns The end of the ISO week.
|
|
151
163
|
*/
|
|
152
164
|
this.endOfISOWeek = (date) => {
|
|
153
|
-
return this.overrides?.endOfISOWeek
|
|
165
|
+
return this.overrides?.endOfISOWeek
|
|
166
|
+
? this.overrides.endOfISOWeek(date)
|
|
167
|
+
: (0, date_fns_1.endOfISOWeek)(date);
|
|
154
168
|
};
|
|
155
169
|
/**
|
|
156
170
|
* Returns the end of the month for the given date.
|
|
@@ -159,7 +173,9 @@ class DateLib {
|
|
|
159
173
|
* @returns The end of the month.
|
|
160
174
|
*/
|
|
161
175
|
this.endOfMonth = (date) => {
|
|
162
|
-
return this.overrides?.endOfMonth
|
|
176
|
+
return this.overrides?.endOfMonth
|
|
177
|
+
? this.overrides.endOfMonth(date)
|
|
178
|
+
: (0, date_fns_1.endOfMonth)(date);
|
|
163
179
|
};
|
|
164
180
|
/**
|
|
165
181
|
* Returns the end of the week for the given date.
|
|
@@ -167,9 +183,10 @@ class DateLib {
|
|
|
167
183
|
* @param date The original date.
|
|
168
184
|
* @returns The end of the week.
|
|
169
185
|
*/
|
|
170
|
-
this.endOfWeek = (date
|
|
171
|
-
return
|
|
172
|
-
|
|
186
|
+
this.endOfWeek = (date) => {
|
|
187
|
+
return this.overrides?.endOfWeek
|
|
188
|
+
? this.overrides.endOfWeek(date, this.options)
|
|
189
|
+
: (0, date_fns_1.endOfWeek)(date, this.options);
|
|
173
190
|
};
|
|
174
191
|
/**
|
|
175
192
|
* Returns the end of the year for the given date.
|
|
@@ -178,7 +195,9 @@ class DateLib {
|
|
|
178
195
|
* @returns The end of the year.
|
|
179
196
|
*/
|
|
180
197
|
this.endOfYear = (date) => {
|
|
181
|
-
return this.overrides?.endOfYear
|
|
198
|
+
return this.overrides?.endOfYear
|
|
199
|
+
? this.overrides.endOfYear(date)
|
|
200
|
+
: (0, date_fns_1.endOfYear)(date);
|
|
182
201
|
};
|
|
183
202
|
/**
|
|
184
203
|
* Formats the given date using the specified format string.
|
|
@@ -187,9 +206,10 @@ class DateLib {
|
|
|
187
206
|
* @param formatStr The format string.
|
|
188
207
|
* @returns The formatted date string.
|
|
189
208
|
*/
|
|
190
|
-
this.format = (date, formatStr
|
|
191
|
-
const formatted = this.overrides?.format
|
|
192
|
-
|
|
209
|
+
this.format = (date, formatStr) => {
|
|
210
|
+
const formatted = this.overrides?.format
|
|
211
|
+
? this.overrides.format(date, formatStr, this.options)
|
|
212
|
+
: (0, date_fns_1.format)(date, formatStr, this.options);
|
|
193
213
|
if (this.options.numerals && this.options.numerals !== "latn") {
|
|
194
214
|
return this.replaceDigits(formatted);
|
|
195
215
|
}
|
|
@@ -202,7 +222,9 @@ class DateLib {
|
|
|
202
222
|
* @returns The ISO week number.
|
|
203
223
|
*/
|
|
204
224
|
this.getISOWeek = (date) => {
|
|
205
|
-
return this.overrides?.getISOWeek
|
|
225
|
+
return this.overrides?.getISOWeek
|
|
226
|
+
? this.overrides.getISOWeek(date)
|
|
227
|
+
: (0, date_fns_1.getISOWeek)(date);
|
|
206
228
|
};
|
|
207
229
|
/**
|
|
208
230
|
* Returns the month of the given date.
|
|
@@ -211,7 +233,9 @@ class DateLib {
|
|
|
211
233
|
* @returns The month.
|
|
212
234
|
*/
|
|
213
235
|
this.getMonth = (date) => {
|
|
214
|
-
return this.overrides?.getMonth
|
|
236
|
+
return this.overrides?.getMonth
|
|
237
|
+
? this.overrides.getMonth(date, this.options)
|
|
238
|
+
: (0, date_fns_1.getMonth)(date, this.options);
|
|
215
239
|
};
|
|
216
240
|
/**
|
|
217
241
|
* Returns the year of the given date.
|
|
@@ -220,7 +244,9 @@ class DateLib {
|
|
|
220
244
|
* @returns The year.
|
|
221
245
|
*/
|
|
222
246
|
this.getYear = (date) => {
|
|
223
|
-
return this.overrides?.getYear
|
|
247
|
+
return this.overrides?.getYear
|
|
248
|
+
? this.overrides.getYear(date, this.options)
|
|
249
|
+
: (0, date_fns_1.getYear)(date, this.options);
|
|
224
250
|
};
|
|
225
251
|
/**
|
|
226
252
|
* Returns the local week number for the given date.
|
|
@@ -228,9 +254,10 @@ class DateLib {
|
|
|
228
254
|
* @param date The date to get the week number for.
|
|
229
255
|
* @returns The week number.
|
|
230
256
|
*/
|
|
231
|
-
this.getWeek = (date
|
|
232
|
-
return
|
|
233
|
-
|
|
257
|
+
this.getWeek = (date) => {
|
|
258
|
+
return this.overrides?.getWeek
|
|
259
|
+
? this.overrides.getWeek(date, this.options)
|
|
260
|
+
: (0, date_fns_1.getWeek)(date, this.options);
|
|
234
261
|
};
|
|
235
262
|
/**
|
|
236
263
|
* Checks if the first date is after the second date.
|
|
@@ -240,8 +267,9 @@ class DateLib {
|
|
|
240
267
|
* @returns True if the first date is after the second date.
|
|
241
268
|
*/
|
|
242
269
|
this.isAfter = (date, dateToCompare) => {
|
|
243
|
-
return
|
|
244
|
-
|
|
270
|
+
return this.overrides?.isAfter
|
|
271
|
+
? this.overrides.isAfter(date, dateToCompare)
|
|
272
|
+
: (0, date_fns_1.isAfter)(date, dateToCompare);
|
|
245
273
|
};
|
|
246
274
|
/**
|
|
247
275
|
* Checks if the first date is before the second date.
|
|
@@ -251,8 +279,9 @@ class DateLib {
|
|
|
251
279
|
* @returns True if the first date is before the second date.
|
|
252
280
|
*/
|
|
253
281
|
this.isBefore = (date, dateToCompare) => {
|
|
254
|
-
return
|
|
255
|
-
|
|
282
|
+
return this.overrides?.isBefore
|
|
283
|
+
? this.overrides.isBefore(date, dateToCompare)
|
|
284
|
+
: (0, date_fns_1.isBefore)(date, dateToCompare);
|
|
256
285
|
};
|
|
257
286
|
/**
|
|
258
287
|
* Checks if the given value is a Date object.
|
|
@@ -261,7 +290,9 @@ class DateLib {
|
|
|
261
290
|
* @returns True if the value is a Date object.
|
|
262
291
|
*/
|
|
263
292
|
this.isDate = (value) => {
|
|
264
|
-
return this.overrides?.isDate
|
|
293
|
+
return this.overrides?.isDate
|
|
294
|
+
? this.overrides.isDate(value)
|
|
295
|
+
: (0, date_fns_1.isDate)(value);
|
|
265
296
|
};
|
|
266
297
|
/**
|
|
267
298
|
* Checks if the given dates are on the same day.
|
|
@@ -271,8 +302,9 @@ class DateLib {
|
|
|
271
302
|
* @returns True if the dates are on the same day.
|
|
272
303
|
*/
|
|
273
304
|
this.isSameDay = (dateLeft, dateRight) => {
|
|
274
|
-
return
|
|
275
|
-
|
|
305
|
+
return this.overrides?.isSameDay
|
|
306
|
+
? this.overrides.isSameDay(dateLeft, dateRight)
|
|
307
|
+
: (0, date_fns_1.isSameDay)(dateLeft, dateRight);
|
|
276
308
|
};
|
|
277
309
|
/**
|
|
278
310
|
* Checks if the given dates are in the same month.
|
|
@@ -282,8 +314,9 @@ class DateLib {
|
|
|
282
314
|
* @returns True if the dates are in the same month.
|
|
283
315
|
*/
|
|
284
316
|
this.isSameMonth = (dateLeft, dateRight) => {
|
|
285
|
-
return
|
|
286
|
-
|
|
317
|
+
return this.overrides?.isSameMonth
|
|
318
|
+
? this.overrides.isSameMonth(dateLeft, dateRight)
|
|
319
|
+
: (0, date_fns_1.isSameMonth)(dateLeft, dateRight);
|
|
287
320
|
};
|
|
288
321
|
/**
|
|
289
322
|
* Checks if the given dates are in the same year.
|
|
@@ -293,8 +326,9 @@ class DateLib {
|
|
|
293
326
|
* @returns True if the dates are in the same year.
|
|
294
327
|
*/
|
|
295
328
|
this.isSameYear = (dateLeft, dateRight) => {
|
|
296
|
-
return
|
|
297
|
-
|
|
329
|
+
return this.overrides?.isSameYear
|
|
330
|
+
? this.overrides.isSameYear(dateLeft, dateRight)
|
|
331
|
+
: (0, date_fns_1.isSameYear)(dateLeft, dateRight);
|
|
298
332
|
};
|
|
299
333
|
/**
|
|
300
334
|
* Returns the latest date in the given array of dates.
|
|
@@ -303,7 +337,7 @@ class DateLib {
|
|
|
303
337
|
* @returns The latest date.
|
|
304
338
|
*/
|
|
305
339
|
this.max = (dates) => {
|
|
306
|
-
return this.overrides?.max
|
|
340
|
+
return this.overrides?.max ? this.overrides.max(dates) : (0, date_fns_1.max)(dates);
|
|
307
341
|
};
|
|
308
342
|
/**
|
|
309
343
|
* Returns the earliest date in the given array of dates.
|
|
@@ -312,7 +346,7 @@ class DateLib {
|
|
|
312
346
|
* @returns The earliest date.
|
|
313
347
|
*/
|
|
314
348
|
this.min = (dates) => {
|
|
315
|
-
return this.overrides?.min
|
|
349
|
+
return this.overrides?.min ? this.overrides.min(dates) : (0, date_fns_1.min)(dates);
|
|
316
350
|
};
|
|
317
351
|
/**
|
|
318
352
|
* Sets the month of the given date.
|
|
@@ -322,7 +356,9 @@ class DateLib {
|
|
|
322
356
|
* @returns The new date with the month set.
|
|
323
357
|
*/
|
|
324
358
|
this.setMonth = (date, month) => {
|
|
325
|
-
return this.overrides?.setMonth
|
|
359
|
+
return this.overrides?.setMonth
|
|
360
|
+
? this.overrides.setMonth(date, month)
|
|
361
|
+
: (0, date_fns_1.setMonth)(date, month);
|
|
326
362
|
};
|
|
327
363
|
/**
|
|
328
364
|
* Sets the year of the given date.
|
|
@@ -332,7 +368,9 @@ class DateLib {
|
|
|
332
368
|
* @returns The new date with the year set.
|
|
333
369
|
*/
|
|
334
370
|
this.setYear = (date, year) => {
|
|
335
|
-
return this.overrides?.setYear
|
|
371
|
+
return this.overrides?.setYear
|
|
372
|
+
? this.overrides.setYear(date, year)
|
|
373
|
+
: (0, date_fns_1.setYear)(date, year);
|
|
336
374
|
};
|
|
337
375
|
/**
|
|
338
376
|
* Returns the start of the broadcast week for the given date.
|
|
@@ -340,9 +378,10 @@ class DateLib {
|
|
|
340
378
|
* @param date The original date.
|
|
341
379
|
* @returns The start of the broadcast week.
|
|
342
380
|
*/
|
|
343
|
-
this.startOfBroadcastWeek = (date
|
|
344
|
-
return
|
|
345
|
-
|
|
381
|
+
this.startOfBroadcastWeek = (date) => {
|
|
382
|
+
return this.overrides?.startOfBroadcastWeek
|
|
383
|
+
? this.overrides.startOfBroadcastWeek(date, this)
|
|
384
|
+
: (0, startOfBroadcastWeek_js_1.startOfBroadcastWeek)(date, this);
|
|
346
385
|
};
|
|
347
386
|
/**
|
|
348
387
|
* Returns the start of the day for the given date.
|
|
@@ -351,7 +390,9 @@ class DateLib {
|
|
|
351
390
|
* @returns The start of the day.
|
|
352
391
|
*/
|
|
353
392
|
this.startOfDay = (date) => {
|
|
354
|
-
return this.overrides?.startOfDay
|
|
393
|
+
return this.overrides?.startOfDay
|
|
394
|
+
? this.overrides.startOfDay(date)
|
|
395
|
+
: (0, date_fns_1.startOfDay)(date);
|
|
355
396
|
};
|
|
356
397
|
/**
|
|
357
398
|
* Returns the start of the ISO week for the given date.
|
|
@@ -360,7 +401,9 @@ class DateLib {
|
|
|
360
401
|
* @returns The start of the ISO week.
|
|
361
402
|
*/
|
|
362
403
|
this.startOfISOWeek = (date) => {
|
|
363
|
-
return this.overrides?.startOfISOWeek
|
|
404
|
+
return this.overrides?.startOfISOWeek
|
|
405
|
+
? this.overrides.startOfISOWeek(date)
|
|
406
|
+
: (0, date_fns_1.startOfISOWeek)(date);
|
|
364
407
|
};
|
|
365
408
|
/**
|
|
366
409
|
* Returns the start of the month for the given date.
|
|
@@ -369,7 +412,9 @@ class DateLib {
|
|
|
369
412
|
* @returns The start of the month.
|
|
370
413
|
*/
|
|
371
414
|
this.startOfMonth = (date) => {
|
|
372
|
-
return this.overrides?.startOfMonth
|
|
415
|
+
return this.overrides?.startOfMonth
|
|
416
|
+
? this.overrides.startOfMonth(date)
|
|
417
|
+
: (0, date_fns_1.startOfMonth)(date);
|
|
373
418
|
};
|
|
374
419
|
/**
|
|
375
420
|
* Returns the start of the week for the given date.
|
|
@@ -378,7 +423,9 @@ class DateLib {
|
|
|
378
423
|
* @returns The start of the week.
|
|
379
424
|
*/
|
|
380
425
|
this.startOfWeek = (date) => {
|
|
381
|
-
return
|
|
426
|
+
return this.overrides?.startOfWeek
|
|
427
|
+
? this.overrides.startOfWeek(date, this.options)
|
|
428
|
+
: (0, date_fns_1.startOfWeek)(date, this.options);
|
|
382
429
|
};
|
|
383
430
|
/**
|
|
384
431
|
* Returns the start of the year for the given date.
|
|
@@ -387,7 +434,9 @@ class DateLib {
|
|
|
387
434
|
* @returns The start of the year.
|
|
388
435
|
*/
|
|
389
436
|
this.startOfYear = (date) => {
|
|
390
|
-
return this.overrides?.startOfYear
|
|
437
|
+
return this.overrides?.startOfYear
|
|
438
|
+
? this.overrides.startOfYear(date)
|
|
439
|
+
: (0, date_fns_1.startOfYear)(date);
|
|
391
440
|
};
|
|
392
441
|
this.options = { locale: en_US_1.enUS, ...options };
|
|
393
442
|
this.overrides = overrides;
|