@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.
@@ -166,345 +166,345 @@ const defaultFormats = {
166
166
  * SOFTWARE.
167
167
  */
168
168
  class AdapterLuxon {
169
+ isMUIAdapter = true;
170
+ isTimezoneCompatible = true;
171
+ lib = 'luxon';
172
+ escapedCharacters = {
173
+ start: "'",
174
+ end: "'"
175
+ };
176
+ formatTokenMap = formatTokenMap;
169
177
  constructor({
170
178
  locale,
171
179
  formats
172
180
  } = {}) {
173
- this.isMUIAdapter = true;
174
- this.isTimezoneCompatible = true;
175
- this.lib = 'luxon';
176
- this.locale = void 0;
177
- this.formats = void 0;
178
- this.escapedCharacters = {
179
- start: "'",
180
- end: "'"
181
- };
182
- this.formatTokenMap = formatTokenMap;
183
- this.setLocaleToValue = value => {
184
- const expectedLocale = this.getCurrentLocaleCode();
185
- if (expectedLocale === value.locale) {
186
- return value;
187
- }
188
- return value.setLocale(expectedLocale);
189
- };
190
- this.date = (value, timezone = 'default') => {
191
- if (value === null) {
192
- return null;
193
- }
194
- if (typeof value === 'undefined') {
195
- // @ts-ignore
196
- return _luxon.DateTime.fromJSDate(new Date(), {
197
- locale: this.locale,
198
- zone: timezone
199
- });
200
- }
201
-
181
+ this.locale = locale || 'en-US';
182
+ this.formats = (0, _extends2.default)({}, defaultFormats, formats);
183
+ }
184
+ setLocaleToValue = value => {
185
+ const expectedLocale = this.getCurrentLocaleCode();
186
+ if (expectedLocale === value.locale) {
187
+ return value;
188
+ }
189
+ return value.setLocale(expectedLocale);
190
+ };
191
+ date = (value, timezone = 'default') => {
192
+ if (value === null) {
193
+ return null;
194
+ }
195
+ if (typeof value === 'undefined') {
202
196
  // @ts-ignore
203
- return _luxon.DateTime.fromISO(value, {
197
+ return _luxon.DateTime.fromJSDate(new Date(), {
204
198
  locale: this.locale,
205
199
  zone: timezone
206
200
  });
207
- };
208
- this.getInvalidDate = () => _luxon.DateTime.fromJSDate(new Date('Invalid Date'));
209
- this.getTimezone = value => {
210
- // When using the system zone, we want to return "system", not something like "Europe/Paris"
211
- if (value.zone.type === 'system') {
212
- return 'system';
213
- }
214
- return value.zoneName;
215
- };
216
- this.setTimezone = (value, timezone) => {
217
- if (!value.zone.equals(_luxon.Info.normalizeZone(timezone))) {
218
- return value.setZone(timezone);
219
- }
220
- return value;
221
- };
222
- this.toJsDate = value => {
223
- return value.toJSDate();
224
- };
225
- this.parse = (value, formatString) => {
226
- if (value === '') {
227
- return null;
228
- }
229
- return _luxon.DateTime.fromFormat(value, formatString, {
230
- locale: this.locale
231
- });
232
- };
233
- this.getCurrentLocaleCode = () => {
234
- return this.locale;
235
- };
236
- /* v8 ignore start */
237
- this.is12HourCycleInCurrentLocale = () => {
238
- if (typeof Intl === 'undefined' || typeof Intl.DateTimeFormat === 'undefined') {
239
- return true; // Luxon defaults to en-US if Intl not found
240
- }
241
- return Boolean(new Intl.DateTimeFormat(this.locale, {
242
- hour: 'numeric'
243
- })?.resolvedOptions()?.hour12);
244
- };
245
- /* v8 ignore stop */
246
- this.expandFormat = format => {
247
- // Extract escaped section to avoid extending them
248
- const catchEscapedSectionsRegexp = /''|'(''|[^'])+('|$)|[^']*/g;
201
+ }
249
202
 
250
- // This RegExp tests if a string is only mad of supported tokens
251
- const validTokens = [...Object.keys(this.formatTokenMap), 'yyyyy'];
252
- const isWordComposedOfTokens = new RegExp(`^(${validTokens.join('|')})+$`);
203
+ // @ts-ignore
204
+ return _luxon.DateTime.fromISO(value, {
205
+ locale: this.locale,
206
+ zone: timezone
207
+ });
208
+ };
209
+ getInvalidDate = () => _luxon.DateTime.fromJSDate(new Date('Invalid Date'));
210
+ getTimezone = value => {
211
+ // When using the system zone, we want to return "system", not something like "Europe/Paris"
212
+ if (value.zone.type === 'system') {
213
+ return 'system';
214
+ }
215
+ return value.zoneName;
216
+ };
217
+ setTimezone = (value, timezone) => {
218
+ if (!value.zone.equals(_luxon.Info.normalizeZone(timezone))) {
219
+ return value.setZone(timezone);
220
+ }
221
+ return value;
222
+ };
223
+ toJsDate = value => {
224
+ return value.toJSDate();
225
+ };
226
+ parse = (value, formatString) => {
227
+ if (value === '') {
228
+ return null;
229
+ }
230
+ return _luxon.DateTime.fromFormat(value, formatString, {
231
+ locale: this.locale
232
+ });
233
+ };
234
+ getCurrentLocaleCode = () => {
235
+ return this.locale;
236
+ };
253
237
 
254
- // Extract words to test if they are a token or a word to escape.
255
- const catchWordsRegexp = /(?:^|[^a-z])([a-z]+)(?:[^a-z]|$)|([a-z]+)/gi;
256
- return format.match(catchEscapedSectionsRegexp).map(token => {
257
- const firstCharacter = token[0];
258
- if (firstCharacter === "'") {
259
- return token;
260
- }
261
- const expandedToken = _luxon.DateTime.expandFormat(token, {
262
- locale: this.locale
263
- });
264
- return expandedToken.replace(catchWordsRegexp, (substring, g1, g2) => {
265
- const word = g1 || g2; // words are either in group 1 or group 2
238
+ /* v8 ignore start */
239
+ is12HourCycleInCurrentLocale = () => {
240
+ if (typeof Intl === 'undefined' || typeof Intl.DateTimeFormat === 'undefined') {
241
+ return true; // Luxon defaults to en-US if Intl not found
242
+ }
243
+ return Boolean(new Intl.DateTimeFormat(this.locale, {
244
+ hour: 'numeric'
245
+ })?.resolvedOptions()?.hour12);
246
+ };
247
+ /* v8 ignore stop */
266
248
 
267
- if (isWordComposedOfTokens.test(word)) {
268
- return substring;
269
- }
270
- return `'${substring}'`;
271
- });
272
- }).join('')
273
- // The returned format can contain `yyyyy` which means year between 4 and 6 digits.
274
- // This value is supported by luxon parser but not luxon formatter.
275
- // To avoid conflicts, we replace it by 4 digits which is enough for most use-cases.
276
- .replace('yyyyy', 'yyyy');
277
- };
278
- this.isValid = value => {
279
- if (value === null) {
280
- return false;
281
- }
282
- return value.isValid;
283
- };
284
- this.format = (value, formatKey) => {
285
- return this.formatByString(value, this.formats[formatKey]);
286
- };
287
- this.formatByString = (value, format) => {
288
- return value.setLocale(this.locale).toFormat(format);
289
- };
290
- this.formatNumber = numberToFormat => {
291
- return numberToFormat;
292
- };
293
- this.isEqual = (value, comparing) => {
294
- if (value === null && comparing === null) {
295
- return true;
296
- }
297
- if (value === null || comparing === null) {
298
- return false;
249
+ expandFormat = format => {
250
+ // Extract escaped section to avoid extending them
251
+ const catchEscapedSectionsRegexp = /''|'(''|[^'])+('|$)|[^']*/g;
252
+
253
+ // This RegExp tests if a string is only mad of supported tokens
254
+ const validTokens = [...Object.keys(this.formatTokenMap), 'yyyyy'];
255
+ const isWordComposedOfTokens = new RegExp(`^(${validTokens.join('|')})+$`);
256
+
257
+ // Extract words to test if they are a token or a word to escape.
258
+ const catchWordsRegexp = /(?:^|[^a-z])([a-z]+)(?:[^a-z]|$)|([a-z]+)/gi;
259
+ return format.match(catchEscapedSectionsRegexp).map(token => {
260
+ const firstCharacter = token[0];
261
+ if (firstCharacter === "'") {
262
+ return token;
299
263
  }
300
- return +value === +comparing;
301
- };
302
- this.isSameYear = (value, comparing) => {
303
- const comparingInValueTimezone = this.setTimezone(comparing, this.getTimezone(value));
304
- return value.hasSame(comparingInValueTimezone, 'year');
305
- };
306
- this.isSameMonth = (value, comparing) => {
307
- const comparingInValueTimezone = this.setTimezone(comparing, this.getTimezone(value));
308
- return value.hasSame(comparingInValueTimezone, 'month');
309
- };
310
- this.isSameDay = (value, comparing) => {
311
- const comparingInValueTimezone = this.setTimezone(comparing, this.getTimezone(value));
312
- return value.hasSame(comparingInValueTimezone, 'day');
313
- };
314
- this.isSameHour = (value, comparing) => {
315
- const comparingInValueTimezone = this.setTimezone(comparing, this.getTimezone(value));
316
- return value.hasSame(comparingInValueTimezone, 'hour');
317
- };
318
- this.isAfter = (value, comparing) => {
319
- return value > comparing;
320
- };
321
- this.isAfterYear = (value, comparing) => {
322
- const comparingInValueTimezone = this.setTimezone(comparing, this.getTimezone(value));
323
- const diff = value.diff(this.endOfYear(comparingInValueTimezone), 'years').toObject();
324
- return diff.years > 0;
325
- };
326
- this.isAfterDay = (value, comparing) => {
327
- const comparingInValueTimezone = this.setTimezone(comparing, this.getTimezone(value));
328
- const diff = value.diff(this.endOfDay(comparingInValueTimezone), 'days').toObject();
329
- return diff.days > 0;
330
- };
331
- this.isBefore = (value, comparing) => {
332
- return value < comparing;
333
- };
334
- this.isBeforeYear = (value, comparing) => {
335
- const comparingInValueTimezone = this.setTimezone(comparing, this.getTimezone(value));
336
- const diff = value.diff(this.startOfYear(comparingInValueTimezone), 'years').toObject();
337
- return diff.years < 0;
338
- };
339
- this.isBeforeDay = (value, comparing) => {
340
- const comparingInValueTimezone = this.setTimezone(comparing, this.getTimezone(value));
341
- const diff = value.diff(this.startOfDay(comparingInValueTimezone), 'days').toObject();
342
- return diff.days < 0;
343
- };
344
- this.isWithinRange = (value, [start, end]) => {
345
- return this.isEqual(value, start) || this.isEqual(value, end) || this.isAfter(value, start) && this.isBefore(value, end);
346
- };
347
- this.startOfYear = value => {
348
- return value.startOf('year');
349
- };
350
- this.startOfMonth = value => {
351
- return value.startOf('month');
352
- };
353
- this.startOfWeek = value => {
354
- return this.setLocaleToValue(value).startOf('week', {
355
- useLocaleWeeks: true
356
- });
357
- };
358
- this.startOfDay = value => {
359
- return value.startOf('day');
360
- };
361
- this.endOfYear = value => {
362
- return value.endOf('year');
363
- };
364
- this.endOfMonth = value => {
365
- return value.endOf('month');
366
- };
367
- this.endOfWeek = value => {
368
- return this.setLocaleToValue(value).endOf('week', {
369
- useLocaleWeeks: true
370
- });
371
- };
372
- this.endOfDay = value => {
373
- return value.endOf('day');
374
- };
375
- this.addYears = (value, amount) => {
376
- return value.plus({
377
- years: amount
378
- });
379
- };
380
- this.addMonths = (value, amount) => {
381
- return value.plus({
382
- months: amount
383
- });
384
- };
385
- this.addWeeks = (value, amount) => {
386
- return value.plus({
387
- weeks: amount
388
- });
389
- };
390
- this.addDays = (value, amount) => {
391
- return value.plus({
392
- days: amount
393
- });
394
- };
395
- this.addHours = (value, amount) => {
396
- return value.plus({
397
- hours: amount
398
- });
399
- };
400
- this.addMinutes = (value, amount) => {
401
- return value.plus({
402
- minutes: amount
403
- });
404
- };
405
- this.addSeconds = (value, amount) => {
406
- return value.plus({
407
- seconds: amount
408
- });
409
- };
410
- this.getYear = value => {
411
- return value.get('year');
412
- };
413
- this.getMonth = value => {
414
- // See https://github.com/moment/luxon/blob/master/docs/moment.md#major-functional-differences
415
- return value.get('month') - 1;
416
- };
417
- this.getDate = value => {
418
- return value.get('day');
419
- };
420
- this.getHours = value => {
421
- return value.get('hour');
422
- };
423
- this.getMinutes = value => {
424
- return value.get('minute');
425
- };
426
- this.getSeconds = value => {
427
- return value.get('second');
428
- };
429
- this.getMilliseconds = value => {
430
- return value.get('millisecond');
431
- };
432
- this.setYear = (value, year) => {
433
- return value.set({
434
- year
435
- });
436
- };
437
- this.setMonth = (value, month) => {
438
- return value.set({
439
- month: month + 1
440
- });
441
- };
442
- this.setDate = (value, date) => {
443
- return value.set({
444
- day: date
445
- });
446
- };
447
- this.setHours = (value, hours) => {
448
- return value.set({
449
- hour: hours
450
- });
451
- };
452
- this.setMinutes = (value, minutes) => {
453
- return value.set({
454
- minute: minutes
455
- });
456
- };
457
- this.setSeconds = (value, seconds) => {
458
- return value.set({
459
- second: seconds
460
- });
461
- };
462
- this.setMilliseconds = (value, milliseconds) => {
463
- return value.set({
464
- millisecond: milliseconds
264
+ const expandedToken = _luxon.DateTime.expandFormat(token, {
265
+ locale: this.locale
465
266
  });
466
- };
467
- this.getDaysInMonth = value => {
468
- return value.daysInMonth;
469
- };
470
- this.getWeekArray = value => {
471
- const firstDay = this.startOfWeek(this.startOfMonth(value));
472
- const lastDay = this.endOfWeek(this.endOfMonth(value));
473
- const {
474
- days
475
- } = lastDay.diff(firstDay, 'days').toObject();
476
- const weeks = [];
477
- new Array(Math.round(days)).fill(0).map((_, i) => i).map(day => firstDay.plus({
478
- days: day
479
- })).forEach((v, i) => {
480
- if (i === 0 || i % 7 === 0 && i > 6) {
481
- weeks.push([v]);
482
- return;
267
+ return expandedToken.replace(catchWordsRegexp, (substring, g1, g2) => {
268
+ const word = g1 || g2; // words are either in group 1 or group 2
269
+
270
+ if (isWordComposedOfTokens.test(word)) {
271
+ return substring;
483
272
  }
484
- weeks[weeks.length - 1].push(v);
273
+ return `'${substring}'`;
485
274
  });
486
- return weeks;
487
- };
488
- this.getWeekNumber = value => {
489
- /* v8 ignore next */
490
- return value.localWeekNumber ?? value.weekNumber;
491
- };
492
- this.getDayOfWeek = value => {
493
- return value.weekday;
494
- };
495
- this.getYearRange = ([start, end]) => {
496
- const startDate = this.startOfYear(start);
497
- const endDate = this.endOfYear(end);
498
- const years = [];
499
- let current = startDate;
500
- while (this.isBefore(current, endDate)) {
501
- years.push(current);
502
- current = this.addYears(current, 1);
275
+ }).join('')
276
+ // The returned format can contain `yyyyy` which means year between 4 and 6 digits.
277
+ // This value is supported by luxon parser but not luxon formatter.
278
+ // To avoid conflicts, we replace it by 4 digits which is enough for most use-cases.
279
+ .replace('yyyyy', 'yyyy');
280
+ };
281
+ isValid = value => {
282
+ if (value === null) {
283
+ return false;
284
+ }
285
+ return value.isValid;
286
+ };
287
+ format = (value, formatKey) => {
288
+ return this.formatByString(value, this.formats[formatKey]);
289
+ };
290
+ formatByString = (value, format) => {
291
+ return value.setLocale(this.locale).toFormat(format);
292
+ };
293
+ formatNumber = numberToFormat => {
294
+ return numberToFormat;
295
+ };
296
+ isEqual = (value, comparing) => {
297
+ if (value === null && comparing === null) {
298
+ return true;
299
+ }
300
+ if (value === null || comparing === null) {
301
+ return false;
302
+ }
303
+ return +value === +comparing;
304
+ };
305
+ isSameYear = (value, comparing) => {
306
+ const comparingInValueTimezone = this.setTimezone(comparing, this.getTimezone(value));
307
+ return value.hasSame(comparingInValueTimezone, 'year');
308
+ };
309
+ isSameMonth = (value, comparing) => {
310
+ const comparingInValueTimezone = this.setTimezone(comparing, this.getTimezone(value));
311
+ return value.hasSame(comparingInValueTimezone, 'month');
312
+ };
313
+ isSameDay = (value, comparing) => {
314
+ const comparingInValueTimezone = this.setTimezone(comparing, this.getTimezone(value));
315
+ return value.hasSame(comparingInValueTimezone, 'day');
316
+ };
317
+ isSameHour = (value, comparing) => {
318
+ const comparingInValueTimezone = this.setTimezone(comparing, this.getTimezone(value));
319
+ return value.hasSame(comparingInValueTimezone, 'hour');
320
+ };
321
+ isAfter = (value, comparing) => {
322
+ return value > comparing;
323
+ };
324
+ isAfterYear = (value, comparing) => {
325
+ const comparingInValueTimezone = this.setTimezone(comparing, this.getTimezone(value));
326
+ const diff = value.diff(this.endOfYear(comparingInValueTimezone), 'years').toObject();
327
+ return diff.years > 0;
328
+ };
329
+ isAfterDay = (value, comparing) => {
330
+ const comparingInValueTimezone = this.setTimezone(comparing, this.getTimezone(value));
331
+ const diff = value.diff(this.endOfDay(comparingInValueTimezone), 'days').toObject();
332
+ return diff.days > 0;
333
+ };
334
+ isBefore = (value, comparing) => {
335
+ return value < comparing;
336
+ };
337
+ isBeforeYear = (value, comparing) => {
338
+ const comparingInValueTimezone = this.setTimezone(comparing, this.getTimezone(value));
339
+ const diff = value.diff(this.startOfYear(comparingInValueTimezone), 'years').toObject();
340
+ return diff.years < 0;
341
+ };
342
+ isBeforeDay = (value, comparing) => {
343
+ const comparingInValueTimezone = this.setTimezone(comparing, this.getTimezone(value));
344
+ const diff = value.diff(this.startOfDay(comparingInValueTimezone), 'days').toObject();
345
+ return diff.days < 0;
346
+ };
347
+ isWithinRange = (value, [start, end]) => {
348
+ return this.isEqual(value, start) || this.isEqual(value, end) || this.isAfter(value, start) && this.isBefore(value, end);
349
+ };
350
+ startOfYear = value => {
351
+ return value.startOf('year');
352
+ };
353
+ startOfMonth = value => {
354
+ return value.startOf('month');
355
+ };
356
+ startOfWeek = value => {
357
+ return this.setLocaleToValue(value).startOf('week', {
358
+ useLocaleWeeks: true
359
+ });
360
+ };
361
+ startOfDay = value => {
362
+ return value.startOf('day');
363
+ };
364
+ endOfYear = value => {
365
+ return value.endOf('year');
366
+ };
367
+ endOfMonth = value => {
368
+ return value.endOf('month');
369
+ };
370
+ endOfWeek = value => {
371
+ return this.setLocaleToValue(value).endOf('week', {
372
+ useLocaleWeeks: true
373
+ });
374
+ };
375
+ endOfDay = value => {
376
+ return value.endOf('day');
377
+ };
378
+ addYears = (value, amount) => {
379
+ return value.plus({
380
+ years: amount
381
+ });
382
+ };
383
+ addMonths = (value, amount) => {
384
+ return value.plus({
385
+ months: amount
386
+ });
387
+ };
388
+ addWeeks = (value, amount) => {
389
+ return value.plus({
390
+ weeks: amount
391
+ });
392
+ };
393
+ addDays = (value, amount) => {
394
+ return value.plus({
395
+ days: amount
396
+ });
397
+ };
398
+ addHours = (value, amount) => {
399
+ return value.plus({
400
+ hours: amount
401
+ });
402
+ };
403
+ addMinutes = (value, amount) => {
404
+ return value.plus({
405
+ minutes: amount
406
+ });
407
+ };
408
+ addSeconds = (value, amount) => {
409
+ return value.plus({
410
+ seconds: amount
411
+ });
412
+ };
413
+ getYear = value => {
414
+ return value.get('year');
415
+ };
416
+ getMonth = value => {
417
+ // See https://github.com/moment/luxon/blob/master/docs/moment.md#major-functional-differences
418
+ return value.get('month') - 1;
419
+ };
420
+ getDate = value => {
421
+ return value.get('day');
422
+ };
423
+ getHours = value => {
424
+ return value.get('hour');
425
+ };
426
+ getMinutes = value => {
427
+ return value.get('minute');
428
+ };
429
+ getSeconds = value => {
430
+ return value.get('second');
431
+ };
432
+ getMilliseconds = value => {
433
+ return value.get('millisecond');
434
+ };
435
+ setYear = (value, year) => {
436
+ return value.set({
437
+ year
438
+ });
439
+ };
440
+ setMonth = (value, month) => {
441
+ return value.set({
442
+ month: month + 1
443
+ });
444
+ };
445
+ setDate = (value, date) => {
446
+ return value.set({
447
+ day: date
448
+ });
449
+ };
450
+ setHours = (value, hours) => {
451
+ return value.set({
452
+ hour: hours
453
+ });
454
+ };
455
+ setMinutes = (value, minutes) => {
456
+ return value.set({
457
+ minute: minutes
458
+ });
459
+ };
460
+ setSeconds = (value, seconds) => {
461
+ return value.set({
462
+ second: seconds
463
+ });
464
+ };
465
+ setMilliseconds = (value, milliseconds) => {
466
+ return value.set({
467
+ millisecond: milliseconds
468
+ });
469
+ };
470
+ getDaysInMonth = value => {
471
+ return value.daysInMonth;
472
+ };
473
+ getWeekArray = value => {
474
+ const firstDay = this.startOfWeek(this.startOfMonth(value));
475
+ const lastDay = this.endOfWeek(this.endOfMonth(value));
476
+ const {
477
+ days
478
+ } = lastDay.diff(firstDay, 'days').toObject();
479
+ const weeks = [];
480
+ new Array(Math.round(days)).fill(0).map((_, i) => i).map(day => firstDay.plus({
481
+ days: day
482
+ })).forEach((v, i) => {
483
+ if (i === 0 || i % 7 === 0 && i > 6) {
484
+ weeks.push([v]);
485
+ return;
503
486
  }
504
- return years;
505
- };
506
- this.locale = locale || 'en-US';
507
- this.formats = (0, _extends2.default)({}, defaultFormats, formats);
508
- }
487
+ weeks[weeks.length - 1].push(v);
488
+ });
489
+ return weeks;
490
+ };
491
+ getWeekNumber = value => {
492
+ /* v8 ignore next */
493
+ return value.localWeekNumber ?? value.weekNumber;
494
+ };
495
+ getDayOfWeek = value => {
496
+ return value.weekday;
497
+ };
498
+ getYearRange = ([start, end]) => {
499
+ const startDate = this.startOfYear(start);
500
+ const endDate = this.endOfYear(end);
501
+ const years = [];
502
+ let current = startDate;
503
+ while (this.isBefore(current, endDate)) {
504
+ years.push(current);
505
+ current = this.addYears(current, 1);
506
+ }
507
+ return years;
508
+ };
509
509
  }
510
510
  exports.AdapterLuxon = AdapterLuxon;