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