@mui/x-date-pickers 8.10.0 → 8.11.0

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