@mui/x-date-pickers 8.10.0 → 8.10.2

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.
@@ -161,405 +161,405 @@ const MISSING_TIMEZONE_PLUGIN = ['Missing timezone plugin', 'To be able to use t
161
161
  * SOFTWARE.
162
162
  */
163
163
  class AdapterDayjs {
164
+ isMUIAdapter = true;
165
+ isTimezoneCompatible = true;
166
+ lib = 'dayjs';
167
+ escapedCharacters = {
168
+ start: '[',
169
+ end: ']'
170
+ };
171
+ formatTokenMap = formatTokenMap;
164
172
  constructor({
165
- locale: _locale,
173
+ locale,
166
174
  formats
167
175
  } = {}) {
168
- this.isMUIAdapter = true;
169
- this.isTimezoneCompatible = true;
170
- this.lib = 'dayjs';
171
- this.locale = void 0;
172
- this.formats = void 0;
173
- this.escapedCharacters = {
174
- start: '[',
175
- end: ']'
176
- };
177
- this.formatTokenMap = formatTokenMap;
178
- this.setLocaleToValue = value => {
179
- const expectedLocale = this.getCurrentLocaleCode();
180
- if (expectedLocale === value.locale()) {
181
- return value;
182
- }
183
- return value.locale(expectedLocale);
184
- };
185
- this.hasUTCPlugin = () => typeof _dayjs.default.utc !== 'undefined';
186
- this.hasTimezonePlugin = () => typeof _dayjs.default.tz !== 'undefined';
187
- this.isSame = (value, comparing, comparisonTemplate) => {
188
- const comparingInValueTimezone = this.setTimezone(comparing, this.getTimezone(value));
189
- return value.format(comparisonTemplate) === comparingInValueTimezone.format(comparisonTemplate);
190
- };
191
- /**
192
- * Replaces "default" by undefined and "system" by the system timezone before passing it to `dayjs`.
193
- */
194
- this.cleanTimezone = timezone => {
195
- switch (timezone) {
196
- case 'default':
197
- {
198
- return undefined;
199
- }
200
- case 'system':
201
- {
202
- return _dayjs.default.tz.guess();
203
- }
204
- default:
205
- {
206
- return timezone;
207
- }
208
- }
209
- };
210
- this.createSystemDate = value => {
211
- let date;
212
- if (this.hasUTCPlugin() && this.hasTimezonePlugin()) {
213
- const timezone = _dayjs.default.tz.guess();
214
- if (timezone === 'UTC') {
215
- date = (0, _dayjs.default)(value);
216
- } /* v8 ignore next 3 */else {
217
- // We can't change the system timezone in the tests
218
- date = _dayjs.default.tz(value, timezone);
176
+ this.locale = locale;
177
+ this.formats = (0, _extends2.default)({}, defaultFormats, formats);
178
+
179
+ // Moved plugins to the constructor to allow for users to use options on the library
180
+ // for reference: https://github.com/mui/mui-x/pull/11151
181
+ _dayjs.default.extend(_customParseFormat.default);
182
+ }
183
+ setLocaleToValue = value => {
184
+ const expectedLocale = this.getCurrentLocaleCode();
185
+ if (expectedLocale === value.locale()) {
186
+ return value;
187
+ }
188
+ return value.locale(expectedLocale);
189
+ };
190
+ hasUTCPlugin = () => typeof _dayjs.default.utc !== 'undefined';
191
+ hasTimezonePlugin = () => typeof _dayjs.default.tz !== 'undefined';
192
+ isSame = (value, comparing, comparisonTemplate) => {
193
+ const comparingInValueTimezone = this.setTimezone(comparing, this.getTimezone(value));
194
+ return value.format(comparisonTemplate) === comparingInValueTimezone.format(comparisonTemplate);
195
+ };
196
+
197
+ /**
198
+ * Replaces "default" by undefined and "system" by the system timezone before passing it to `dayjs`.
199
+ */
200
+ cleanTimezone = timezone => {
201
+ switch (timezone) {
202
+ case 'default':
203
+ {
204
+ return undefined;
205
+ }
206
+ case 'system':
207
+ {
208
+ return _dayjs.default.tz.guess();
219
209
  }
220
- } else {
210
+ default:
211
+ {
212
+ return timezone;
213
+ }
214
+ }
215
+ };
216
+ createSystemDate = value => {
217
+ let date;
218
+ if (this.hasUTCPlugin() && this.hasTimezonePlugin()) {
219
+ const timezone = _dayjs.default.tz.guess();
220
+ if (timezone === 'UTC') {
221
221
  date = (0, _dayjs.default)(value);
222
+ } /* v8 ignore next 3 */else {
223
+ // We can't change the system timezone in the tests
224
+ date = _dayjs.default.tz(value, timezone);
222
225
  }
223
- return this.setLocaleToValue(date);
224
- };
225
- this.createUTCDate = value => {
226
- /* v8 ignore next 3 */
227
- if (!this.hasUTCPlugin()) {
228
- throw new Error(MISSING_UTC_PLUGIN);
229
- }
230
- return this.setLocaleToValue(_dayjs.default.utc(value));
231
- };
232
- this.createTZDate = (value, timezone) => {
233
- /* v8 ignore next 3 */
234
- if (!this.hasUTCPlugin()) {
235
- throw new Error(MISSING_UTC_PLUGIN);
226
+ } else {
227
+ date = (0, _dayjs.default)(value);
228
+ }
229
+ return this.setLocaleToValue(date);
230
+ };
231
+ createUTCDate = value => {
232
+ /* v8 ignore next 3 */
233
+ if (!this.hasUTCPlugin()) {
234
+ throw new Error(MISSING_UTC_PLUGIN);
235
+ }
236
+ return this.setLocaleToValue(_dayjs.default.utc(value));
237
+ };
238
+ createTZDate = (value, timezone) => {
239
+ /* v8 ignore next 3 */
240
+ if (!this.hasUTCPlugin()) {
241
+ throw new Error(MISSING_UTC_PLUGIN);
242
+ }
243
+
244
+ /* v8 ignore next 3 */
245
+ if (!this.hasTimezonePlugin()) {
246
+ throw new Error(MISSING_TIMEZONE_PLUGIN);
247
+ }
248
+ const keepLocalTime = value !== undefined && !value.endsWith('Z');
249
+ return this.setLocaleToValue((0, _dayjs.default)(value).tz(this.cleanTimezone(timezone), keepLocalTime));
250
+ };
251
+ getLocaleFormats = () => {
252
+ const locales = _dayjs.default.Ls;
253
+ const locale = this.locale || 'en';
254
+ let localeObject = locales[locale];
255
+ if (localeObject === undefined) {
256
+ /* v8 ignore start */
257
+ if (process.env.NODE_ENV !== 'production') {
258
+ (0, _warning.warnOnce)(['MUI X: Your locale has not been found.', 'Either the locale key is not a supported one. Locales supported by dayjs are available here: https://github.com/iamkun/dayjs/tree/dev/src/locale.', "Or you forget to import the locale from 'dayjs/locale/{localeUsed}'", 'fallback on English locale.']);
236
259
  }
260
+ /* v8 ignore stop */
261
+ localeObject = locales.en;
262
+ }
263
+ return localeObject.formats;
264
+ };
237
265
 
266
+ /**
267
+ * If the new day does not have the same offset as the old one (when switching to summer day time for example),
268
+ * Then dayjs will not automatically adjust the offset (moment does).
269
+ * We have to parse again the value to make sure the `fixOffset` method is applied.
270
+ * See https://github.com/iamkun/dayjs/blob/b3624de619d6e734cd0ffdbbd3502185041c1b60/src/plugin/timezone/index.js#L72
271
+ */
272
+ adjustOffset = value => {
273
+ if (!this.hasTimezonePlugin()) {
274
+ return value;
275
+ }
276
+ const timezone = this.getTimezone(value);
277
+ if (timezone !== 'UTC') {
278
+ const fixedValue = value.tz(this.cleanTimezone(timezone), true);
279
+ // TODO: Simplify the case when we raise the `dayjs` peer dep to 1.11.12 (https://github.com/iamkun/dayjs/releases/tag/v1.11.12)
238
280
  /* v8 ignore next 3 */
239
- if (!this.hasTimezonePlugin()) {
240
- throw new Error(MISSING_TIMEZONE_PLUGIN);
241
- }
242
- const keepLocalTime = value !== undefined && !value.endsWith('Z');
243
- return this.setLocaleToValue((0, _dayjs.default)(value).tz(this.cleanTimezone(timezone), keepLocalTime));
244
- };
245
- this.getLocaleFormats = () => {
246
- const locales = _dayjs.default.Ls;
247
- const locale = this.locale || 'en';
248
- let localeObject = locales[locale];
249
- if (localeObject === undefined) {
250
- /* v8 ignore start */
251
- if (process.env.NODE_ENV !== 'production') {
252
- (0, _warning.warnOnce)(['MUI X: Your locale has not been found.', 'Either the locale key is not a supported one. Locales supported by dayjs are available here: https://github.com/iamkun/dayjs/tree/dev/src/locale.', "Or you forget to import the locale from 'dayjs/locale/{localeUsed}'", 'fallback on English locale.']);
253
- }
254
- /* v8 ignore stop */
255
- localeObject = locales.en;
256
- }
257
- return localeObject.formats;
258
- };
259
- /**
260
- * If the new day does not have the same offset as the old one (when switching to summer day time for example),
261
- * Then dayjs will not automatically adjust the offset (moment does).
262
- * We have to parse again the value to make sure the `fixOffset` method is applied.
263
- * See https://github.com/iamkun/dayjs/blob/b3624de619d6e734cd0ffdbbd3502185041c1b60/src/plugin/timezone/index.js#L72
264
- */
265
- this.adjustOffset = value => {
266
- if (!this.hasTimezonePlugin()) {
281
+ // @ts-ignore
282
+ if (fixedValue.$offset === (value.$offset ?? 0)) {
267
283
  return value;
268
284
  }
269
- const timezone = this.getTimezone(value);
270
- if (timezone !== 'UTC') {
271
- const fixedValue = value.tz(this.cleanTimezone(timezone), true);
272
- // TODO: Simplify the case when we raise the `dayjs` peer dep to 1.11.12 (https://github.com/iamkun/dayjs/releases/tag/v1.11.12)
273
- /* v8 ignore next 3 */
274
- // @ts-ignore
275
- if (fixedValue.$offset === (value.$offset ?? 0)) {
276
- return value;
277
- }
278
- // Change only what is needed to avoid creating a new object with unwanted data
279
- // Especially important when used in an environment where utc or timezone dates are used only in some places
280
- // Reference: https://github.com/mui/mui-x/issues/13290
281
- // @ts-ignore
282
- value.$offset = fixedValue.$offset;
285
+ // Change only what is needed to avoid creating a new object with unwanted data
286
+ // Especially important when used in an environment where utc or timezone dates are used only in some places
287
+ // Reference: https://github.com/mui/mui-x/issues/13290
288
+ // @ts-ignore
289
+ value.$offset = fixedValue.$offset;
290
+ }
291
+ return value;
292
+ };
293
+ date = (value, timezone = 'default') => {
294
+ if (value === null) {
295
+ return null;
296
+ }
297
+ if (timezone === 'UTC') {
298
+ return this.createUTCDate(value);
299
+ }
300
+ if (timezone === 'system' || timezone === 'default' && !this.hasTimezonePlugin()) {
301
+ return this.createSystemDate(value);
302
+ }
303
+ return this.createTZDate(value, timezone);
304
+ };
305
+ getInvalidDate = () => (0, _dayjs.default)(new Date('Invalid date'));
306
+ getTimezone = value => {
307
+ if (this.hasTimezonePlugin()) {
308
+ // @ts-ignore
309
+ const zone = value.$x?.$timezone;
310
+ if (zone) {
311
+ return zone;
283
312
  }
313
+ }
314
+ if (this.hasUTCPlugin() && value.isUTC()) {
315
+ return 'UTC';
316
+ }
317
+ return 'system';
318
+ };
319
+ setTimezone = (value, timezone) => {
320
+ if (this.getTimezone(value) === timezone) {
284
321
  return value;
285
- };
286
- this.date = (value, timezone = 'default') => {
287
- if (value === null) {
288
- return null;
289
- }
290
- if (timezone === 'UTC') {
291
- return this.createUTCDate(value);
292
- }
293
- if (timezone === 'system' || timezone === 'default' && !this.hasTimezonePlugin()) {
294
- return this.createSystemDate(value);
295
- }
296
- return this.createTZDate(value, timezone);
297
- };
298
- this.getInvalidDate = () => (0, _dayjs.default)(new Date('Invalid date'));
299
- this.getTimezone = value => {
300
- if (this.hasTimezonePlugin()) {
301
- // @ts-ignore
302
- const zone = value.$x?.$timezone;
303
- if (zone) {
304
- return zone;
305
- }
306
- }
307
- if (this.hasUTCPlugin() && value.isUTC()) {
308
- return 'UTC';
309
- }
310
- return 'system';
311
- };
312
- this.setTimezone = (value, timezone) => {
313
- if (this.getTimezone(value) === timezone) {
314
- return value;
315
- }
316
- if (timezone === 'UTC') {
317
- /* v8 ignore next 3 */
318
- if (!this.hasUTCPlugin()) {
319
- throw new Error(MISSING_UTC_PLUGIN);
320
- }
321
- return value.utc();
322
+ }
323
+ if (timezone === 'UTC') {
324
+ /* v8 ignore next 3 */
325
+ if (!this.hasUTCPlugin()) {
326
+ throw new Error(MISSING_UTC_PLUGIN);
322
327
  }
328
+ return value.utc();
329
+ }
323
330
 
324
- // We know that we have the UTC plugin.
325
- // Otherwise, the value timezone would always equal "system".
326
- // And it would be caught by the first "if" of this method.
327
- if (timezone === 'system') {
328
- return value.local();
331
+ // We know that we have the UTC plugin.
332
+ // Otherwise, the value timezone would always equal "system".
333
+ // And it would be caught by the first "if" of this method.
334
+ if (timezone === 'system') {
335
+ return value.local();
336
+ }
337
+ if (!this.hasTimezonePlugin()) {
338
+ if (timezone === 'default') {
339
+ return value;
329
340
  }
330
- if (!this.hasTimezonePlugin()) {
331
- if (timezone === 'default') {
332
- return value;
333
- }
334
341
 
335
- /* v8 ignore next */
336
- throw new Error(MISSING_TIMEZONE_PLUGIN);
337
- }
338
- return this.setLocaleToValue(_dayjs.default.tz(value, this.cleanTimezone(timezone)));
339
- };
340
- this.toJsDate = value => {
341
- return value.toDate();
342
- };
343
- this.parse = (value, format) => {
344
- if (value === '') {
345
- return null;
346
- }
347
- return (0, _dayjs.default)(value, format, this.locale, true);
348
- };
349
- this.getCurrentLocaleCode = () => {
350
- return this.locale || 'en';
351
- };
352
- this.is12HourCycleInCurrentLocale = () => {
353
342
  /* v8 ignore next */
354
- return /A|a/.test(this.getLocaleFormats().LT || '');
355
- };
356
- this.expandFormat = format => {
357
- const localeFormats = this.getLocaleFormats();
358
-
359
- // @see https://github.com/iamkun/dayjs/blob/dev/src/plugin/localizedFormat/index.js
360
- const t = formatBis => formatBis.replace(/(\[[^\]]+])|(MMMM|MM|DD|dddd)/g, (_, a, b) => a || b.slice(1));
361
- return format.replace(/(\[[^\]]+])|(LTS?|l{1,4}|L{1,4})/g, (_, a, b) => {
362
- const B = b && b.toUpperCase();
363
- return a || localeFormats[b] || t(localeFormats[B]);
364
- });
365
- };
366
- this.isValid = value => {
367
- if (value == null) {
368
- return false;
369
- }
370
- return value.isValid();
371
- };
372
- this.format = (value, formatKey) => {
373
- return this.formatByString(value, this.formats[formatKey]);
374
- };
375
- this.formatByString = (value, formatString) => {
376
- return this.setLocaleToValue(value).format(formatString);
377
- };
378
- this.formatNumber = numberToFormat => {
379
- return numberToFormat;
380
- };
381
- this.isEqual = (value, comparing) => {
382
- if (value === null && comparing === null) {
383
- return true;
384
- }
385
- if (value === null || comparing === null) {
386
- return false;
387
- }
388
- return value.toDate().getTime() === comparing.toDate().getTime();
389
- };
390
- this.isSameYear = (value, comparing) => {
391
- return this.isSame(value, comparing, 'YYYY');
392
- };
393
- this.isSameMonth = (value, comparing) => {
394
- return this.isSame(value, comparing, 'YYYY-MM');
395
- };
396
- this.isSameDay = (value, comparing) => {
397
- return this.isSame(value, comparing, 'YYYY-MM-DD');
398
- };
399
- this.isSameHour = (value, comparing) => {
400
- return value.isSame(comparing, 'hour');
401
- };
402
- this.isAfter = (value, comparing) => {
403
- return value > comparing;
404
- };
405
- this.isAfterYear = (value, comparing) => {
406
- if (!this.hasUTCPlugin()) {
407
- return value.isAfter(comparing, 'year');
408
- }
409
- return !this.isSameYear(value, comparing) && value.utc() > comparing.utc();
410
- };
411
- this.isAfterDay = (value, comparing) => {
412
- if (!this.hasUTCPlugin()) {
413
- return value.isAfter(comparing, 'day');
414
- }
415
- return !this.isSameDay(value, comparing) && value.utc() > comparing.utc();
416
- };
417
- this.isBefore = (value, comparing) => {
418
- return value < comparing;
419
- };
420
- this.isBeforeYear = (value, comparing) => {
421
- if (!this.hasUTCPlugin()) {
422
- return value.isBefore(comparing, 'year');
423
- }
424
- return !this.isSameYear(value, comparing) && value.utc() < comparing.utc();
425
- };
426
- this.isBeforeDay = (value, comparing) => {
427
- if (!this.hasUTCPlugin()) {
428
- return value.isBefore(comparing, 'day');
429
- }
430
- return !this.isSameDay(value, comparing) && value.utc() < comparing.utc();
431
- };
432
- this.isWithinRange = (value, [start, end]) => {
433
- return value >= start && value <= end;
434
- };
435
- this.startOfYear = value => {
436
- return this.adjustOffset(value.startOf('year'));
437
- };
438
- this.startOfMonth = value => {
439
- return this.adjustOffset(value.startOf('month'));
440
- };
441
- this.startOfWeek = value => {
442
- return this.adjustOffset(this.setLocaleToValue(value).startOf('week'));
443
- };
444
- this.startOfDay = value => {
445
- return this.adjustOffset(value.startOf('day'));
446
- };
447
- this.endOfYear = value => {
448
- return this.adjustOffset(value.endOf('year'));
449
- };
450
- this.endOfMonth = value => {
451
- return this.adjustOffset(value.endOf('month'));
452
- };
453
- this.endOfWeek = value => {
454
- return this.adjustOffset(this.setLocaleToValue(value).endOf('week'));
455
- };
456
- this.endOfDay = value => {
457
- return this.adjustOffset(value.endOf('day'));
458
- };
459
- this.addYears = (value, amount) => {
460
- return this.adjustOffset(value.add(amount, 'year'));
461
- };
462
- this.addMonths = (value, amount) => {
463
- return this.adjustOffset(value.add(amount, 'month'));
464
- };
465
- this.addWeeks = (value, amount) => {
466
- return this.adjustOffset(value.add(amount, 'week'));
467
- };
468
- this.addDays = (value, amount) => {
469
- return this.adjustOffset(value.add(amount, 'day'));
470
- };
471
- this.addHours = (value, amount) => {
472
- return this.adjustOffset(value.add(amount, 'hour'));
473
- };
474
- this.addMinutes = (value, amount) => {
475
- return this.adjustOffset(value.add(amount, 'minute'));
476
- };
477
- this.addSeconds = (value, amount) => {
478
- return this.adjustOffset(value.add(amount, 'second'));
479
- };
480
- this.getYear = value => {
481
- return value.year();
482
- };
483
- this.getMonth = value => {
484
- return value.month();
485
- };
486
- this.getDate = value => {
487
- return value.date();
488
- };
489
- this.getHours = value => {
490
- return value.hour();
491
- };
492
- this.getMinutes = value => {
493
- return value.minute();
494
- };
495
- this.getSeconds = value => {
496
- return value.second();
497
- };
498
- this.getMilliseconds = value => {
499
- return value.millisecond();
500
- };
501
- this.setYear = (value, year) => {
502
- return this.adjustOffset(value.set('year', year));
503
- };
504
- this.setMonth = (value, month) => {
505
- return this.adjustOffset(value.set('month', month));
506
- };
507
- this.setDate = (value, date) => {
508
- return this.adjustOffset(value.set('date', date));
509
- };
510
- this.setHours = (value, hours) => {
511
- return this.adjustOffset(value.set('hour', hours));
512
- };
513
- this.setMinutes = (value, minutes) => {
514
- return this.adjustOffset(value.set('minute', minutes));
515
- };
516
- this.setSeconds = (value, seconds) => {
517
- return this.adjustOffset(value.set('second', seconds));
518
- };
519
- this.setMilliseconds = (value, milliseconds) => {
520
- return this.adjustOffset(value.set('millisecond', milliseconds));
521
- };
522
- this.getDaysInMonth = value => {
523
- return value.daysInMonth();
524
- };
525
- this.getWeekArray = value => {
526
- const start = this.startOfWeek(this.startOfMonth(value));
527
- const end = this.endOfWeek(this.endOfMonth(value));
528
- let count = 0;
529
- let current = start;
530
- const nestedWeeks = [];
531
- while (current < end) {
532
- const weekNumber = Math.floor(count / 7);
533
- nestedWeeks[weekNumber] = nestedWeeks[weekNumber] || [];
534
- nestedWeeks[weekNumber].push(current);
535
- current = this.addDays(current, 1);
536
- count += 1;
537
- }
538
- return nestedWeeks;
539
- };
540
- this.getWeekNumber = value => {
541
- return value.week();
542
- };
543
- this.getYearRange = ([start, end]) => {
544
- const startDate = this.startOfYear(start);
545
- const endDate = this.endOfYear(end);
546
- const years = [];
547
- let current = startDate;
548
- while (this.isBefore(current, endDate)) {
549
- years.push(current);
550
- current = this.addYears(current, 1);
551
- }
552
- return years;
553
- };
554
- this.locale = _locale;
555
- this.formats = (0, _extends2.default)({}, defaultFormats, formats);
343
+ throw new Error(MISSING_TIMEZONE_PLUGIN);
344
+ }
345
+ return this.setLocaleToValue(_dayjs.default.tz(value, this.cleanTimezone(timezone)));
346
+ };
347
+ toJsDate = value => {
348
+ return value.toDate();
349
+ };
350
+ parse = (value, format) => {
351
+ if (value === '') {
352
+ return null;
353
+ }
354
+ return (0, _dayjs.default)(value, format, this.locale, true);
355
+ };
356
+ getCurrentLocaleCode = () => {
357
+ return this.locale || 'en';
358
+ };
359
+ is12HourCycleInCurrentLocale = () => {
360
+ /* v8 ignore next */
361
+ return /A|a/.test(this.getLocaleFormats().LT || '');
362
+ };
363
+ expandFormat = format => {
364
+ const localeFormats = this.getLocaleFormats();
556
365
 
557
- // Moved plugins to the constructor to allow for users to use options on the library
558
- // for reference: https://github.com/mui/mui-x/pull/11151
559
- _dayjs.default.extend(_customParseFormat.default);
560
- }
366
+ // @see https://github.com/iamkun/dayjs/blob/dev/src/plugin/localizedFormat/index.js
367
+ const t = formatBis => formatBis.replace(/(\[[^\]]+])|(MMMM|MM|DD|dddd)/g, (_, a, b) => a || b.slice(1));
368
+ return format.replace(/(\[[^\]]+])|(LTS?|l{1,4}|L{1,4})/g, (_, a, b) => {
369
+ const B = b && b.toUpperCase();
370
+ return a || localeFormats[b] || t(localeFormats[B]);
371
+ });
372
+ };
373
+ isValid = value => {
374
+ if (value == null) {
375
+ return false;
376
+ }
377
+ return value.isValid();
378
+ };
379
+ format = (value, formatKey) => {
380
+ return this.formatByString(value, this.formats[formatKey]);
381
+ };
382
+ formatByString = (value, formatString) => {
383
+ return this.setLocaleToValue(value).format(formatString);
384
+ };
385
+ formatNumber = numberToFormat => {
386
+ return numberToFormat;
387
+ };
388
+ isEqual = (value, comparing) => {
389
+ if (value === null && comparing === null) {
390
+ return true;
391
+ }
392
+ if (value === null || comparing === null) {
393
+ return false;
394
+ }
395
+ return value.toDate().getTime() === comparing.toDate().getTime();
396
+ };
397
+ isSameYear = (value, comparing) => {
398
+ return this.isSame(value, comparing, 'YYYY');
399
+ };
400
+ isSameMonth = (value, comparing) => {
401
+ return this.isSame(value, comparing, 'YYYY-MM');
402
+ };
403
+ isSameDay = (value, comparing) => {
404
+ return this.isSame(value, comparing, 'YYYY-MM-DD');
405
+ };
406
+ isSameHour = (value, comparing) => {
407
+ return value.isSame(comparing, 'hour');
408
+ };
409
+ isAfter = (value, comparing) => {
410
+ return value > comparing;
411
+ };
412
+ isAfterYear = (value, comparing) => {
413
+ if (!this.hasUTCPlugin()) {
414
+ return value.isAfter(comparing, 'year');
415
+ }
416
+ return !this.isSameYear(value, comparing) && value.utc() > comparing.utc();
417
+ };
418
+ isAfterDay = (value, comparing) => {
419
+ if (!this.hasUTCPlugin()) {
420
+ return value.isAfter(comparing, 'day');
421
+ }
422
+ return !this.isSameDay(value, comparing) && value.utc() > comparing.utc();
423
+ };
424
+ isBefore = (value, comparing) => {
425
+ return value < comparing;
426
+ };
427
+ isBeforeYear = (value, comparing) => {
428
+ if (!this.hasUTCPlugin()) {
429
+ return value.isBefore(comparing, 'year');
430
+ }
431
+ return !this.isSameYear(value, comparing) && value.utc() < comparing.utc();
432
+ };
433
+ isBeforeDay = (value, comparing) => {
434
+ if (!this.hasUTCPlugin()) {
435
+ return value.isBefore(comparing, 'day');
436
+ }
437
+ return !this.isSameDay(value, comparing) && value.utc() < comparing.utc();
438
+ };
439
+ isWithinRange = (value, [start, end]) => {
440
+ return value >= start && value <= end;
441
+ };
442
+ startOfYear = value => {
443
+ return this.adjustOffset(value.startOf('year'));
444
+ };
445
+ startOfMonth = value => {
446
+ return this.adjustOffset(value.startOf('month'));
447
+ };
448
+ startOfWeek = value => {
449
+ return this.adjustOffset(this.setLocaleToValue(value).startOf('week'));
450
+ };
451
+ startOfDay = value => {
452
+ return this.adjustOffset(value.startOf('day'));
453
+ };
454
+ endOfYear = value => {
455
+ return this.adjustOffset(value.endOf('year'));
456
+ };
457
+ endOfMonth = value => {
458
+ return this.adjustOffset(value.endOf('month'));
459
+ };
460
+ endOfWeek = value => {
461
+ return this.adjustOffset(this.setLocaleToValue(value).endOf('week'));
462
+ };
463
+ endOfDay = value => {
464
+ return this.adjustOffset(value.endOf('day'));
465
+ };
466
+ addYears = (value, amount) => {
467
+ return this.adjustOffset(value.add(amount, 'year'));
468
+ };
469
+ addMonths = (value, amount) => {
470
+ return this.adjustOffset(value.add(amount, 'month'));
471
+ };
472
+ addWeeks = (value, amount) => {
473
+ return this.adjustOffset(value.add(amount, 'week'));
474
+ };
475
+ addDays = (value, amount) => {
476
+ return this.adjustOffset(value.add(amount, 'day'));
477
+ };
478
+ addHours = (value, amount) => {
479
+ return this.adjustOffset(value.add(amount, 'hour'));
480
+ };
481
+ addMinutes = (value, amount) => {
482
+ return this.adjustOffset(value.add(amount, 'minute'));
483
+ };
484
+ addSeconds = (value, amount) => {
485
+ return this.adjustOffset(value.add(amount, 'second'));
486
+ };
487
+ getYear = value => {
488
+ return value.year();
489
+ };
490
+ getMonth = value => {
491
+ return value.month();
492
+ };
493
+ getDate = value => {
494
+ return value.date();
495
+ };
496
+ getHours = value => {
497
+ return value.hour();
498
+ };
499
+ getMinutes = value => {
500
+ return value.minute();
501
+ };
502
+ getSeconds = value => {
503
+ return value.second();
504
+ };
505
+ getMilliseconds = value => {
506
+ return value.millisecond();
507
+ };
508
+ setYear = (value, year) => {
509
+ return this.adjustOffset(value.set('year', year));
510
+ };
511
+ setMonth = (value, month) => {
512
+ return this.adjustOffset(value.set('month', month));
513
+ };
514
+ setDate = (value, date) => {
515
+ return this.adjustOffset(value.set('date', date));
516
+ };
517
+ setHours = (value, hours) => {
518
+ return this.adjustOffset(value.set('hour', hours));
519
+ };
520
+ setMinutes = (value, minutes) => {
521
+ return this.adjustOffset(value.set('minute', minutes));
522
+ };
523
+ setSeconds = (value, seconds) => {
524
+ return this.adjustOffset(value.set('second', seconds));
525
+ };
526
+ setMilliseconds = (value, milliseconds) => {
527
+ return this.adjustOffset(value.set('millisecond', milliseconds));
528
+ };
529
+ getDaysInMonth = value => {
530
+ return value.daysInMonth();
531
+ };
532
+ getWeekArray = value => {
533
+ const start = this.startOfWeek(this.startOfMonth(value));
534
+ const end = this.endOfWeek(this.endOfMonth(value));
535
+ let count = 0;
536
+ let current = start;
537
+ const nestedWeeks = [];
538
+ while (current < end) {
539
+ const weekNumber = Math.floor(count / 7);
540
+ nestedWeeks[weekNumber] = nestedWeeks[weekNumber] || [];
541
+ nestedWeeks[weekNumber].push(current);
542
+ current = this.addDays(current, 1);
543
+ count += 1;
544
+ }
545
+ return nestedWeeks;
546
+ };
547
+ getWeekNumber = value => {
548
+ return value.week();
549
+ };
561
550
  getDayOfWeek(value) {
562
551
  return value.day() + 1;
563
552
  }
553
+ getYearRange = ([start, end]) => {
554
+ const startDate = this.startOfYear(start);
555
+ const endDate = this.endOfYear(end);
556
+ const years = [];
557
+ let current = startDate;
558
+ while (this.isBefore(current, endDate)) {
559
+ years.push(current);
560
+ current = this.addYears(current, 1);
561
+ }
562
+ return years;
563
+ };
564
564
  }
565
565
  exports.AdapterDayjs = AdapterDayjs;