@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.
@@ -155,317 +155,314 @@ const MISSING_TIMEZONE_PLUGIN = ['Missing timezone plugin', 'To be able to use t
155
155
  * SOFTWARE.
156
156
  */
157
157
  class AdapterMoment {
158
+ isMUIAdapter = true;
159
+ isTimezoneCompatible = true;
160
+ lib = 'moment';
161
+ escapedCharacters = {
162
+ start: '[',
163
+ end: ']'
164
+ };
165
+ formatTokenMap = formatTokenMap;
158
166
  constructor({
159
167
  locale,
160
168
  formats,
161
169
  instance
162
170
  } = {}) {
163
- this.isMUIAdapter = true;
164
- this.isTimezoneCompatible = true;
165
- this.lib = 'moment';
166
- this.moment = void 0;
167
- this.locale = void 0;
168
- this.formats = void 0;
169
- this.escapedCharacters = {
170
- start: '[',
171
- end: ']'
172
- };
173
- this.formatTokenMap = formatTokenMap;
174
- this.setLocaleToValue = value => {
175
- const expectedLocale = this.getCurrentLocaleCode();
176
- if (expectedLocale === value.locale()) {
177
- return value;
178
- }
179
- return value.locale(expectedLocale);
180
- };
181
- this.hasTimezonePlugin = () => typeof this.moment.tz !== 'undefined';
182
- this.createSystemDate = value => {
183
- const parsedValue = this.moment(value).local();
184
- if (this.locale === undefined) {
185
- return parsedValue;
186
- }
187
- return parsedValue.locale(this.locale);
188
- };
189
- this.createUTCDate = value => {
190
- const parsedValue = this.moment.utc(value);
191
- if (this.locale === undefined) {
192
- return parsedValue;
193
- }
194
- return parsedValue.locale(this.locale);
195
- };
196
- this.createTZDate = (value, timezone) => {
171
+ this.moment = instance || _moment.default;
172
+ this.locale = locale;
173
+ this.formats = (0, _extends2.default)({}, defaultFormats, formats);
174
+ }
175
+ setLocaleToValue = value => {
176
+ const expectedLocale = this.getCurrentLocaleCode();
177
+ if (expectedLocale === value.locale()) {
178
+ return value;
179
+ }
180
+ return value.locale(expectedLocale);
181
+ };
182
+ hasTimezonePlugin = () => typeof this.moment.tz !== 'undefined';
183
+ createSystemDate = value => {
184
+ const parsedValue = this.moment(value).local();
185
+ if (this.locale === undefined) {
186
+ return parsedValue;
187
+ }
188
+ return parsedValue.locale(this.locale);
189
+ };
190
+ createUTCDate = value => {
191
+ const parsedValue = this.moment.utc(value);
192
+ if (this.locale === undefined) {
193
+ return parsedValue;
194
+ }
195
+ return parsedValue.locale(this.locale);
196
+ };
197
+ createTZDate = (value, timezone) => {
198
+ /* v8 ignore next 3 */
199
+ if (!this.hasTimezonePlugin()) {
200
+ throw new Error(MISSING_TIMEZONE_PLUGIN);
201
+ }
202
+ const parsedValue = timezone === 'default' ? this.moment(value) : this.moment.tz(value, timezone);
203
+ if (this.locale === undefined) {
204
+ return parsedValue;
205
+ }
206
+ return parsedValue.locale(this.locale);
207
+ };
208
+ date = (value, timezone = 'default') => {
209
+ if (value === null) {
210
+ return null;
211
+ }
212
+ if (timezone === 'UTC') {
213
+ return this.createUTCDate(value);
214
+ }
215
+ if (timezone === 'system' || timezone === 'default' && !this.hasTimezonePlugin()) {
216
+ return this.createSystemDate(value);
217
+ }
218
+ return this.createTZDate(value, timezone);
219
+ };
220
+ getInvalidDate = () => this.moment(new Date('Invalid Date'));
221
+ getTimezone = value => {
222
+ // @ts-ignore
223
+ // eslint-disable-next-line no-underscore-dangle
224
+ const zone = value._z?.name;
225
+ const defaultZone = value.isUTC() ? 'UTC' : 'system';
226
+
227
+ // @ts-ignore
228
+ return zone ?? this.moment.defaultZone?.name ?? defaultZone;
229
+ };
230
+ setTimezone = (value, timezone) => {
231
+ if (this.getTimezone(value) === timezone) {
232
+ return value;
233
+ }
234
+ if (timezone === 'UTC') {
235
+ return value.clone().utc();
236
+ }
237
+ if (timezone === 'system') {
238
+ return value.clone().local();
239
+ }
240
+ if (!this.hasTimezonePlugin()) {
197
241
  /* v8 ignore next 3 */
198
- if (!this.hasTimezonePlugin()) {
242
+ if (timezone !== 'default') {
199
243
  throw new Error(MISSING_TIMEZONE_PLUGIN);
200
244
  }
201
- const parsedValue = timezone === 'default' ? this.moment(value) : this.moment.tz(value, timezone);
202
- if (this.locale === undefined) {
203
- return parsedValue;
204
- }
205
- return parsedValue.locale(this.locale);
206
- };
207
- this.date = (value, timezone = 'default') => {
208
- if (value === null) {
209
- return null;
210
- }
211
- if (timezone === 'UTC') {
212
- return this.createUTCDate(value);
213
- }
214
- if (timezone === 'system' || timezone === 'default' && !this.hasTimezonePlugin()) {
215
- return this.createSystemDate(value);
216
- }
217
- return this.createTZDate(value, timezone);
218
- };
219
- this.getInvalidDate = () => this.moment(new Date('Invalid Date'));
220
- this.getTimezone = value => {
221
- // @ts-ignore
222
- // eslint-disable-next-line no-underscore-dangle
223
- const zone = value._z?.name;
224
- const defaultZone = value.isUTC() ? 'UTC' : 'system';
225
-
226
- // @ts-ignore
227
- return zone ?? this.moment.defaultZone?.name ?? defaultZone;
228
- };
229
- this.setTimezone = (value, timezone) => {
230
- if (this.getTimezone(value) === timezone) {
231
- return value;
232
- }
233
- if (timezone === 'UTC') {
234
- return value.clone().utc();
235
- }
236
- if (timezone === 'system') {
237
- return value.clone().local();
238
- }
239
- if (!this.hasTimezonePlugin()) {
240
- /* v8 ignore next 3 */
241
- if (timezone !== 'default') {
242
- throw new Error(MISSING_TIMEZONE_PLUGIN);
243
- }
244
- return value;
245
- }
246
- const cleanZone = timezone === 'default' ?
247
- // @ts-ignore
248
- this.moment.defaultZone?.name ?? 'system' : timezone;
249
- if (cleanZone === 'system') {
250
- return value.clone().local();
251
- }
252
- const newValue = value.clone();
253
- newValue.tz(cleanZone);
254
- return newValue;
255
- };
256
- this.toJsDate = value => {
257
- return value.toDate();
258
- };
259
- this.parse = (value, format) => {
260
- if (value === '') {
261
- return null;
262
- }
263
- if (this.locale) {
264
- return this.moment(value, format, this.locale, true);
265
- }
266
- return this.moment(value, format, true);
267
- };
268
- this.getCurrentLocaleCode = () => {
269
- return this.locale || _moment.default.locale();
270
- };
271
- this.is12HourCycleInCurrentLocale = () => {
272
- return /A|a/.test(_moment.default.localeData(this.getCurrentLocaleCode()).longDateFormat('LT'));
273
- };
274
- this.expandFormat = format => {
275
- // @see https://github.com/moment/moment/blob/develop/src/lib/format/format.js#L6
276
- const localFormattingTokens = /(\[[^[]*\])|(\\)?(LTS|LT|LL?L?L?|l{1,4})|./g;
277
- return format.match(localFormattingTokens).map(token => {
278
- const firstCharacter = token[0];
279
- if (firstCharacter === 'L' || firstCharacter === ';') {
280
- return _moment.default.localeData(this.getCurrentLocaleCode()).longDateFormat(token);
281
- }
282
- return token;
283
- }).join('');
284
- };
285
- this.isValid = value => {
286
- if (value == null) {
287
- return false;
288
- }
289
- return value.isValid();
290
- };
291
- this.format = (value, formatKey) => {
292
- return this.formatByString(value, this.formats[formatKey]);
293
- };
294
- this.formatByString = (value, formatString) => {
295
- const clonedDate = value.clone();
296
- clonedDate.locale(this.getCurrentLocaleCode());
297
- return clonedDate.format(formatString);
298
- };
299
- this.formatNumber = numberToFormat => {
300
- return numberToFormat;
301
- };
302
- this.isEqual = (value, comparing) => {
303
- if (value === null && comparing === null) {
304
- return true;
305
- }
306
- if (value === null || comparing === null) {
307
- return false;
245
+ return value;
246
+ }
247
+ const cleanZone = timezone === 'default' ?
248
+ // @ts-ignore
249
+ this.moment.defaultZone?.name ?? 'system' : timezone;
250
+ if (cleanZone === 'system') {
251
+ return value.clone().local();
252
+ }
253
+ const newValue = value.clone();
254
+ newValue.tz(cleanZone);
255
+ return newValue;
256
+ };
257
+ toJsDate = value => {
258
+ return value.toDate();
259
+ };
260
+ parse = (value, format) => {
261
+ if (value === '') {
262
+ return null;
263
+ }
264
+ if (this.locale) {
265
+ return this.moment(value, format, this.locale, true);
266
+ }
267
+ return this.moment(value, format, true);
268
+ };
269
+ getCurrentLocaleCode = () => {
270
+ return this.locale || _moment.default.locale();
271
+ };
272
+ is12HourCycleInCurrentLocale = () => {
273
+ return /A|a/.test(_moment.default.localeData(this.getCurrentLocaleCode()).longDateFormat('LT'));
274
+ };
275
+ expandFormat = format => {
276
+ // @see https://github.com/moment/moment/blob/develop/src/lib/format/format.js#L6
277
+ const localFormattingTokens = /(\[[^[]*\])|(\\)?(LTS|LT|LL?L?L?|l{1,4})|./g;
278
+ return format.match(localFormattingTokens).map(token => {
279
+ const firstCharacter = token[0];
280
+ if (firstCharacter === 'L' || firstCharacter === ';') {
281
+ return _moment.default.localeData(this.getCurrentLocaleCode()).longDateFormat(token);
308
282
  }
309
- return value.isSame(comparing);
310
- };
311
- this.isSameYear = (value, comparing) => {
312
- return value.isSame(comparing, 'year');
313
- };
314
- this.isSameMonth = (value, comparing) => {
315
- return value.isSame(comparing, 'month');
316
- };
317
- this.isSameDay = (value, comparing) => {
318
- return value.isSame(comparing, 'day');
319
- };
320
- this.isSameHour = (value, comparing) => {
321
- return value.isSame(comparing, 'hour');
322
- };
323
- this.isAfter = (value, comparing) => {
324
- return value.isAfter(comparing);
325
- };
326
- this.isAfterYear = (value, comparing) => {
327
- return value.isAfter(comparing, 'year');
328
- };
329
- this.isAfterDay = (value, comparing) => {
330
- return value.isAfter(comparing, 'day');
331
- };
332
- this.isBefore = (value, comparing) => {
333
- return value.isBefore(comparing);
334
- };
335
- this.isBeforeYear = (value, comparing) => {
336
- return value.isBefore(comparing, 'year');
337
- };
338
- this.isBeforeDay = (value, comparing) => {
339
- return value.isBefore(comparing, 'day');
340
- };
341
- this.isWithinRange = (value, [start, end]) => {
342
- return value.isBetween(start, end, null, '[]');
343
- };
344
- this.startOfYear = value => {
345
- return value.clone().startOf('year');
346
- };
347
- this.startOfMonth = value => {
348
- return value.clone().startOf('month');
349
- };
350
- this.startOfWeek = value => {
351
- return this.setLocaleToValue(value.clone()).startOf('week');
352
- };
353
- this.startOfDay = value => {
354
- return value.clone().startOf('day');
355
- };
356
- this.endOfYear = value => {
357
- return value.clone().endOf('year');
358
- };
359
- this.endOfMonth = value => {
360
- return value.clone().endOf('month');
361
- };
362
- this.endOfWeek = value => {
363
- return this.setLocaleToValue(value.clone()).endOf('week');
364
- };
365
- this.endOfDay = value => {
366
- return value.clone().endOf('day');
367
- };
368
- this.addYears = (value, amount) => {
369
- return amount < 0 ? value.clone().subtract(Math.abs(amount), 'years') : value.clone().add(amount, 'years');
370
- };
371
- this.addMonths = (value, amount) => {
372
- return amount < 0 ? value.clone().subtract(Math.abs(amount), 'months') : value.clone().add(amount, 'months');
373
- };
374
- this.addWeeks = (value, amount) => {
375
- return amount < 0 ? value.clone().subtract(Math.abs(amount), 'weeks') : value.clone().add(amount, 'weeks');
376
- };
377
- this.addDays = (value, amount) => {
378
- return amount < 0 ? value.clone().subtract(Math.abs(amount), 'days') : value.clone().add(amount, 'days');
379
- };
380
- this.addHours = (value, amount) => {
381
- return amount < 0 ? value.clone().subtract(Math.abs(amount), 'hours') : value.clone().add(amount, 'hours');
382
- };
383
- this.addMinutes = (value, amount) => {
384
- return amount < 0 ? value.clone().subtract(Math.abs(amount), 'minutes') : value.clone().add(amount, 'minutes');
385
- };
386
- this.addSeconds = (value, amount) => {
387
- return amount < 0 ? value.clone().subtract(Math.abs(amount), 'seconds') : value.clone().add(amount, 'seconds');
388
- };
389
- this.getYear = value => {
390
- return value.get('year');
391
- };
392
- this.getMonth = value => {
393
- return value.get('month');
394
- };
395
- this.getDate = value => {
396
- return value.get('date');
397
- };
398
- this.getHours = value => {
399
- return value.get('hours');
400
- };
401
- this.getMinutes = value => {
402
- return value.get('minutes');
403
- };
404
- this.getSeconds = value => {
405
- return value.get('seconds');
406
- };
407
- this.getMilliseconds = value => {
408
- return value.get('milliseconds');
409
- };
410
- this.setYear = (value, year) => {
411
- return value.clone().year(year);
412
- };
413
- this.setMonth = (value, month) => {
414
- return value.clone().month(month);
415
- };
416
- this.setDate = (value, date) => {
417
- return value.clone().date(date);
418
- };
419
- this.setHours = (value, hours) => {
420
- return value.clone().hours(hours);
421
- };
422
- this.setMinutes = (value, minutes) => {
423
- return value.clone().minutes(minutes);
424
- };
425
- this.setSeconds = (value, seconds) => {
426
- return value.clone().seconds(seconds);
427
- };
428
- this.setMilliseconds = (value, milliseconds) => {
429
- return value.clone().milliseconds(milliseconds);
430
- };
431
- this.getDaysInMonth = value => {
432
- return value.daysInMonth();
433
- };
434
- this.getWeekArray = value => {
435
- const start = this.startOfWeek(this.startOfMonth(value));
436
- const end = this.endOfWeek(this.endOfMonth(value));
437
- let count = 0;
438
- let current = start;
439
- let currentDayOfYear = current.get('dayOfYear');
440
- const nestedWeeks = [];
441
- while (current.isBefore(end)) {
442
- const weekNumber = Math.floor(count / 7);
443
- nestedWeeks[weekNumber] = nestedWeeks[weekNumber] || [];
444
- nestedWeeks[weekNumber].push(current);
445
- const prevDayOfYear = currentDayOfYear;
446
- current = this.addDays(current, 1);
447
- currentDayOfYear = current.get('dayOfYear');
283
+ return token;
284
+ }).join('');
285
+ };
286
+ isValid = value => {
287
+ if (value == null) {
288
+ return false;
289
+ }
290
+ return value.isValid();
291
+ };
292
+ format = (value, formatKey) => {
293
+ return this.formatByString(value, this.formats[formatKey]);
294
+ };
295
+ formatByString = (value, formatString) => {
296
+ const clonedDate = value.clone();
297
+ clonedDate.locale(this.getCurrentLocaleCode());
298
+ return clonedDate.format(formatString);
299
+ };
300
+ formatNumber = numberToFormat => {
301
+ return numberToFormat;
302
+ };
303
+ isEqual = (value, comparing) => {
304
+ if (value === null && comparing === null) {
305
+ return true;
306
+ }
307
+ if (value === null || comparing === null) {
308
+ return false;
309
+ }
310
+ return value.isSame(comparing);
311
+ };
312
+ isSameYear = (value, comparing) => {
313
+ return value.isSame(comparing, 'year');
314
+ };
315
+ isSameMonth = (value, comparing) => {
316
+ return value.isSame(comparing, 'month');
317
+ };
318
+ isSameDay = (value, comparing) => {
319
+ return value.isSame(comparing, 'day');
320
+ };
321
+ isSameHour = (value, comparing) => {
322
+ return value.isSame(comparing, 'hour');
323
+ };
324
+ isAfter = (value, comparing) => {
325
+ return value.isAfter(comparing);
326
+ };
327
+ isAfterYear = (value, comparing) => {
328
+ return value.isAfter(comparing, 'year');
329
+ };
330
+ isAfterDay = (value, comparing) => {
331
+ return value.isAfter(comparing, 'day');
332
+ };
333
+ isBefore = (value, comparing) => {
334
+ return value.isBefore(comparing);
335
+ };
336
+ isBeforeYear = (value, comparing) => {
337
+ return value.isBefore(comparing, 'year');
338
+ };
339
+ isBeforeDay = (value, comparing) => {
340
+ return value.isBefore(comparing, 'day');
341
+ };
342
+ isWithinRange = (value, [start, end]) => {
343
+ return value.isBetween(start, end, null, '[]');
344
+ };
345
+ startOfYear = value => {
346
+ return value.clone().startOf('year');
347
+ };
348
+ startOfMonth = value => {
349
+ return value.clone().startOf('month');
350
+ };
351
+ startOfWeek = value => {
352
+ return this.setLocaleToValue(value.clone()).startOf('week');
353
+ };
354
+ startOfDay = value => {
355
+ return value.clone().startOf('day');
356
+ };
357
+ endOfYear = value => {
358
+ return value.clone().endOf('year');
359
+ };
360
+ endOfMonth = value => {
361
+ return value.clone().endOf('month');
362
+ };
363
+ endOfWeek = value => {
364
+ return this.setLocaleToValue(value.clone()).endOf('week');
365
+ };
366
+ endOfDay = value => {
367
+ return value.clone().endOf('day');
368
+ };
369
+ addYears = (value, amount) => {
370
+ return amount < 0 ? value.clone().subtract(Math.abs(amount), 'years') : value.clone().add(amount, 'years');
371
+ };
372
+ addMonths = (value, amount) => {
373
+ return amount < 0 ? value.clone().subtract(Math.abs(amount), 'months') : value.clone().add(amount, 'months');
374
+ };
375
+ addWeeks = (value, amount) => {
376
+ return amount < 0 ? value.clone().subtract(Math.abs(amount), 'weeks') : value.clone().add(amount, 'weeks');
377
+ };
378
+ addDays = (value, amount) => {
379
+ return amount < 0 ? value.clone().subtract(Math.abs(amount), 'days') : value.clone().add(amount, 'days');
380
+ };
381
+ addHours = (value, amount) => {
382
+ return amount < 0 ? value.clone().subtract(Math.abs(amount), 'hours') : value.clone().add(amount, 'hours');
383
+ };
384
+ addMinutes = (value, amount) => {
385
+ return amount < 0 ? value.clone().subtract(Math.abs(amount), 'minutes') : value.clone().add(amount, 'minutes');
386
+ };
387
+ addSeconds = (value, amount) => {
388
+ return amount < 0 ? value.clone().subtract(Math.abs(amount), 'seconds') : value.clone().add(amount, 'seconds');
389
+ };
390
+ getYear = value => {
391
+ return value.get('year');
392
+ };
393
+ getMonth = value => {
394
+ return value.get('month');
395
+ };
396
+ getDate = value => {
397
+ return value.get('date');
398
+ };
399
+ getHours = value => {
400
+ return value.get('hours');
401
+ };
402
+ getMinutes = value => {
403
+ return value.get('minutes');
404
+ };
405
+ getSeconds = value => {
406
+ return value.get('seconds');
407
+ };
408
+ getMilliseconds = value => {
409
+ return value.get('milliseconds');
410
+ };
411
+ setYear = (value, year) => {
412
+ return value.clone().year(year);
413
+ };
414
+ setMonth = (value, month) => {
415
+ return value.clone().month(month);
416
+ };
417
+ setDate = (value, date) => {
418
+ return value.clone().date(date);
419
+ };
420
+ setHours = (value, hours) => {
421
+ return value.clone().hours(hours);
422
+ };
423
+ setMinutes = (value, minutes) => {
424
+ return value.clone().minutes(minutes);
425
+ };
426
+ setSeconds = (value, seconds) => {
427
+ return value.clone().seconds(seconds);
428
+ };
429
+ setMilliseconds = (value, milliseconds) => {
430
+ return value.clone().milliseconds(milliseconds);
431
+ };
432
+ getDaysInMonth = value => {
433
+ return value.daysInMonth();
434
+ };
435
+ getWeekArray = value => {
436
+ const start = this.startOfWeek(this.startOfMonth(value));
437
+ const end = this.endOfWeek(this.endOfMonth(value));
438
+ let count = 0;
439
+ let current = start;
440
+ let currentDayOfYear = current.get('dayOfYear');
441
+ const nestedWeeks = [];
442
+ while (current.isBefore(end)) {
443
+ const weekNumber = Math.floor(count / 7);
444
+ nestedWeeks[weekNumber] = nestedWeeks[weekNumber] || [];
445
+ nestedWeeks[weekNumber].push(current);
446
+ const prevDayOfYear = currentDayOfYear;
447
+ current = this.addDays(current, 1);
448
+ currentDayOfYear = current.get('dayOfYear');
448
449
 
449
- // If there is a TZ change at midnight, adding 1 day may only increase the date by 23 hours to 11pm
450
- // To fix, bump the date into the next day (add 12 hours) and then revert to the start of the day
451
- // See https://github.com/moment/moment/issues/4743#issuecomment-811306874 for context.
452
- if (prevDayOfYear === currentDayOfYear) {
453
- current = current.add(12, 'h').startOf('day');
454
- }
455
- count += 1;
450
+ // If there is a TZ change at midnight, adding 1 day may only increase the date by 23 hours to 11pm
451
+ // To fix, bump the date into the next day (add 12 hours) and then revert to the start of the day
452
+ // See https://github.com/moment/moment/issues/4743#issuecomment-811306874 for context.
453
+ if (prevDayOfYear === currentDayOfYear) {
454
+ current = current.add(12, 'h').startOf('day');
456
455
  }
457
- return nestedWeeks;
458
- };
459
- this.getWeekNumber = value => {
460
- return value.week();
461
- };
462
- this.getDayOfWeek = value => {
463
- return value.day() + 1;
464
- };
465
- this.moment = instance || _moment.default;
466
- this.locale = locale;
467
- this.formats = (0, _extends2.default)({}, defaultFormats, formats);
468
- }
456
+ count += 1;
457
+ }
458
+ return nestedWeeks;
459
+ };
460
+ getWeekNumber = value => {
461
+ return value.week();
462
+ };
463
+ getDayOfWeek = value => {
464
+ return value.day() + 1;
465
+ };
469
466
  getYearRange([start, end]) {
470
467
  const startDate = this.startOfYear(start);
471
468
  const endDate = this.endOfYear(end);