@mui/x-date-pickers 6.18.7 → 6.19.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 (136) hide show
  1. package/AdapterDateFns/AdapterDateFns.d.ts +4 -24
  2. package/AdapterDateFns/AdapterDateFns.js +11 -272
  3. package/AdapterDateFnsBase/AdapterDateFnsBase.d.ts +65 -0
  4. package/AdapterDateFnsBase/AdapterDateFnsBase.js +308 -0
  5. package/AdapterDateFnsBase/index.d.ts +1 -0
  6. package/AdapterDateFnsBase/index.js +1 -0
  7. package/AdapterDateFnsBase/package.json +6 -0
  8. package/AdapterDateFnsJalali/AdapterDateFnsJalali.d.ts +1 -0
  9. package/AdapterDateFnsV3/AdapterDateFnsV3.d.ts +88 -0
  10. package/AdapterDateFnsV3/AdapterDateFnsV3.js +358 -0
  11. package/AdapterDateFnsV3/index.d.ts +1 -0
  12. package/AdapterDateFnsV3/index.js +1 -0
  13. package/AdapterDateFnsV3/package.json +6 -0
  14. package/AdapterLuxon/AdapterLuxon.js +0 -1
  15. package/CHANGELOG.md +106 -0
  16. package/DateCalendar/useCalendarState.js +0 -1
  17. package/DatePicker/DatePickerToolbar.d.ts +2 -2
  18. package/DatePicker/DatePickerToolbar.js +2 -7
  19. package/DateTimePicker/DateTimePickerTabs.js +6 -3
  20. package/DigitalClock/DigitalClock.js +1 -0
  21. package/DigitalClock/DigitalClock.types.d.ts +5 -0
  22. package/MonthCalendar/MonthCalendar.js +0 -1
  23. package/MultiSectionDigitalClock/MultiSectionDigitalClock.js +1 -0
  24. package/MultiSectionDigitalClock/MultiSectionDigitalClock.types.d.ts +5 -0
  25. package/PickersLayout/pickersLayoutClasses.js +3 -2
  26. package/PickersLayout/usePickerLayout.js +2 -1
  27. package/TimeClock/Clock.js +0 -1
  28. package/TimeClock/ClockPointer.js +0 -1
  29. package/TimeClock/TimeClock.js +1 -0
  30. package/TimeClock/TimeClock.types.d.ts +5 -0
  31. package/YearCalendar/YearCalendar.js +0 -1
  32. package/hooks/useClearableField.d.ts +1 -1
  33. package/hooks/useClearableField.js +3 -3
  34. package/index.js +1 -1
  35. package/internals/hooks/useClockReferenceDate.js +0 -1
  36. package/internals/hooks/useField/useField.utils.js +0 -2
  37. package/internals/hooks/useViews.js +0 -1
  38. package/internals/models/helpers.d.ts +1 -0
  39. package/internals/models/props/tabs.d.ts +1 -0
  40. package/legacy/AdapterDateFns/AdapterDateFns.js +278 -529
  41. package/legacy/AdapterDateFnsBase/AdapterDateFnsBase.js +308 -0
  42. package/legacy/AdapterDateFnsBase/index.js +1 -0
  43. package/legacy/AdapterDateFnsV3/AdapterDateFnsV3.js +376 -0
  44. package/legacy/AdapterDateFnsV3/index.js +1 -0
  45. package/legacy/AdapterLuxon/AdapterLuxon.js +0 -1
  46. package/legacy/AdapterMomentHijri/AdapterMomentHijri.js +5 -6
  47. package/legacy/AdapterMomentJalaali/AdapterMomentJalaali.js +5 -6
  48. package/legacy/DateCalendar/PickersSlideTransition.js +8 -9
  49. package/legacy/DateCalendar/useCalendarState.js +0 -1
  50. package/legacy/DatePicker/DatePickerToolbar.js +2 -7
  51. package/legacy/DateTimePicker/DateTimePickerTabs.js +6 -3
  52. package/legacy/DigitalClock/DigitalClock.js +1 -0
  53. package/legacy/MonthCalendar/MonthCalendar.js +0 -1
  54. package/legacy/MonthCalendar/PickersMonth.js +4 -5
  55. package/legacy/MultiSectionDigitalClock/MultiSectionDigitalClock.js +1 -0
  56. package/legacy/PickersDay/PickersDay.js +5 -6
  57. package/legacy/PickersLayout/PickersLayout.js +5 -6
  58. package/legacy/PickersLayout/pickersLayoutClasses.js +3 -2
  59. package/legacy/PickersLayout/usePickerLayout.js +2 -1
  60. package/legacy/TimeClock/Clock.js +0 -1
  61. package/legacy/TimeClock/ClockNumber.js +4 -5
  62. package/legacy/TimeClock/ClockPointer.js +0 -1
  63. package/legacy/TimeClock/TimeClock.js +1 -0
  64. package/legacy/TimePicker/TimePickerToolbar.js +1 -2
  65. package/legacy/YearCalendar/PickersYear.js +4 -5
  66. package/legacy/YearCalendar/YearCalendar.js +0 -1
  67. package/legacy/hooks/useClearableField.js +3 -3
  68. package/legacy/index.js +1 -1
  69. package/legacy/internals/components/PickersModalDialog.js +3 -4
  70. package/legacy/internals/hooks/useClockReferenceDate.js +0 -1
  71. package/legacy/internals/hooks/useField/useField.utils.js +0 -2
  72. package/legacy/internals/hooks/useViews.js +0 -1
  73. package/legacy/locales/index.js +1 -0
  74. package/legacy/locales/plPL.js +0 -1
  75. package/legacy/locales/svSE.js +0 -1
  76. package/legacy/locales/urPK.js +0 -1
  77. package/locales/index.d.ts +1 -0
  78. package/locales/index.js +1 -0
  79. package/locales/plPL.js +0 -1
  80. package/locales/svSE.js +0 -1
  81. package/locales/urPK.js +0 -1
  82. package/modern/AdapterDateFns/AdapterDateFns.js +11 -271
  83. package/modern/AdapterDateFnsBase/AdapterDateFnsBase.js +307 -0
  84. package/modern/AdapterDateFnsBase/index.js +1 -0
  85. package/modern/AdapterDateFnsV3/AdapterDateFnsV3.js +358 -0
  86. package/modern/AdapterDateFnsV3/index.js +1 -0
  87. package/modern/AdapterLuxon/AdapterLuxon.js +0 -1
  88. package/modern/DateCalendar/useCalendarState.js +0 -1
  89. package/modern/DatePicker/DatePickerToolbar.js +2 -7
  90. package/modern/DateTimePicker/DateTimePickerTabs.js +6 -3
  91. package/modern/DigitalClock/DigitalClock.js +1 -0
  92. package/modern/MonthCalendar/MonthCalendar.js +0 -1
  93. package/modern/MultiSectionDigitalClock/MultiSectionDigitalClock.js +1 -0
  94. package/modern/PickersLayout/pickersLayoutClasses.js +3 -2
  95. package/modern/PickersLayout/usePickerLayout.js +2 -1
  96. package/modern/TimeClock/Clock.js +0 -1
  97. package/modern/TimeClock/ClockPointer.js +0 -1
  98. package/modern/TimeClock/TimeClock.js +1 -0
  99. package/modern/YearCalendar/YearCalendar.js +0 -1
  100. package/modern/hooks/useClearableField.js +3 -3
  101. package/modern/index.js +1 -1
  102. package/modern/internals/hooks/useClockReferenceDate.js +0 -1
  103. package/modern/internals/hooks/useField/useField.utils.js +0 -2
  104. package/modern/internals/hooks/useViews.js +0 -1
  105. package/modern/locales/index.js +1 -0
  106. package/modern/locales/plPL.js +0 -1
  107. package/modern/locales/svSE.js +0 -1
  108. package/modern/locales/urPK.js +0 -1
  109. package/node/AdapterDateFns/AdapterDateFns.js +11 -271
  110. package/node/AdapterDateFnsBase/AdapterDateFnsBase.js +315 -0
  111. package/node/AdapterDateFnsBase/index.js +12 -0
  112. package/node/AdapterDateFnsV3/AdapterDateFnsV3.js +366 -0
  113. package/node/AdapterDateFnsV3/index.js +12 -0
  114. package/node/AdapterLuxon/AdapterLuxon.js +0 -1
  115. package/node/DateCalendar/useCalendarState.js +0 -1
  116. package/node/DatePicker/DatePickerToolbar.js +0 -4
  117. package/node/DateTimePicker/DateTimePickerTabs.js +7 -4
  118. package/node/DigitalClock/DigitalClock.js +1 -0
  119. package/node/MonthCalendar/MonthCalendar.js +0 -1
  120. package/node/MultiSectionDigitalClock/MultiSectionDigitalClock.js +1 -0
  121. package/node/PickersLayout/pickersLayoutClasses.js +5 -3
  122. package/node/PickersLayout/usePickerLayout.js +2 -1
  123. package/node/TimeClock/Clock.js +0 -1
  124. package/node/TimeClock/ClockPointer.js +0 -1
  125. package/node/TimeClock/TimeClock.js +1 -0
  126. package/node/YearCalendar/YearCalendar.js +0 -1
  127. package/node/hooks/useClearableField.js +3 -3
  128. package/node/index.js +1 -1
  129. package/node/internals/hooks/useClockReferenceDate.js +0 -1
  130. package/node/internals/hooks/useField/useField.utils.js +0 -2
  131. package/node/internals/hooks/useViews.js +0 -1
  132. package/node/locales/index.js +11 -0
  133. package/node/locales/plPL.js +0 -1
  134. package/node/locales/svSE.js +0 -1
  135. package/node/locales/urPK.js +0 -1
  136. package/package.json +2 -2
@@ -1,4 +1,3 @@
1
- import _extends from "@babel/runtime/helpers/esm/extends";
2
1
  /* eslint-disable class-methods-use-this */
3
2
  import addDays from 'date-fns/addDays';
4
3
  import addSeconds from 'date-fns/addSeconds';
@@ -57,202 +56,7 @@ import isWithinInterval from 'date-fns/isWithinInterval';
57
56
  import defaultLocale from 'date-fns/locale/en-US';
58
57
  // @ts-ignore
59
58
  import longFormatters from 'date-fns/_lib/format/longFormatters';
60
- const formatTokenMap = {
61
- // Year
62
- y: {
63
- sectionType: 'year',
64
- contentType: 'digit',
65
- maxLength: 4
66
- },
67
- yy: 'year',
68
- yyy: {
69
- sectionType: 'year',
70
- contentType: 'digit',
71
- maxLength: 4
72
- },
73
- yyyy: 'year',
74
- // Month
75
- M: {
76
- sectionType: 'month',
77
- contentType: 'digit',
78
- maxLength: 2
79
- },
80
- MM: 'month',
81
- MMMM: {
82
- sectionType: 'month',
83
- contentType: 'letter'
84
- },
85
- MMM: {
86
- sectionType: 'month',
87
- contentType: 'letter'
88
- },
89
- L: {
90
- sectionType: 'month',
91
- contentType: 'digit',
92
- maxLength: 2
93
- },
94
- LL: 'month',
95
- LLL: {
96
- sectionType: 'month',
97
- contentType: 'letter'
98
- },
99
- LLLL: {
100
- sectionType: 'month',
101
- contentType: 'letter'
102
- },
103
- // Day of the month
104
- d: {
105
- sectionType: 'day',
106
- contentType: 'digit',
107
- maxLength: 2
108
- },
109
- dd: 'day',
110
- do: {
111
- sectionType: 'day',
112
- contentType: 'digit-with-letter'
113
- },
114
- // Day of the week
115
- E: {
116
- sectionType: 'weekDay',
117
- contentType: 'letter'
118
- },
119
- EE: {
120
- sectionType: 'weekDay',
121
- contentType: 'letter'
122
- },
123
- EEE: {
124
- sectionType: 'weekDay',
125
- contentType: 'letter'
126
- },
127
- EEEE: {
128
- sectionType: 'weekDay',
129
- contentType: 'letter'
130
- },
131
- EEEEE: {
132
- sectionType: 'weekDay',
133
- contentType: 'letter'
134
- },
135
- i: {
136
- sectionType: 'weekDay',
137
- contentType: 'digit',
138
- maxLength: 1
139
- },
140
- ii: 'weekDay',
141
- iii: {
142
- sectionType: 'weekDay',
143
- contentType: 'letter'
144
- },
145
- iiii: {
146
- sectionType: 'weekDay',
147
- contentType: 'letter'
148
- },
149
- e: {
150
- sectionType: 'weekDay',
151
- contentType: 'digit',
152
- maxLength: 1
153
- },
154
- ee: 'weekDay',
155
- eee: {
156
- sectionType: 'weekDay',
157
- contentType: 'letter'
158
- },
159
- eeee: {
160
- sectionType: 'weekDay',
161
- contentType: 'letter'
162
- },
163
- eeeee: {
164
- sectionType: 'weekDay',
165
- contentType: 'letter'
166
- },
167
- eeeeee: {
168
- sectionType: 'weekDay',
169
- contentType: 'letter'
170
- },
171
- c: {
172
- sectionType: 'weekDay',
173
- contentType: 'digit',
174
- maxLength: 1
175
- },
176
- cc: 'weekDay',
177
- ccc: {
178
- sectionType: 'weekDay',
179
- contentType: 'letter'
180
- },
181
- cccc: {
182
- sectionType: 'weekDay',
183
- contentType: 'letter'
184
- },
185
- ccccc: {
186
- sectionType: 'weekDay',
187
- contentType: 'letter'
188
- },
189
- cccccc: {
190
- sectionType: 'weekDay',
191
- contentType: 'letter'
192
- },
193
- // Meridiem
194
- a: 'meridiem',
195
- aa: 'meridiem',
196
- aaa: 'meridiem',
197
- // Hours
198
- H: {
199
- sectionType: 'hours',
200
- contentType: 'digit',
201
- maxLength: 2
202
- },
203
- HH: 'hours',
204
- h: {
205
- sectionType: 'hours',
206
- contentType: 'digit',
207
- maxLength: 2
208
- },
209
- hh: 'hours',
210
- // Minutes
211
- m: {
212
- sectionType: 'minutes',
213
- contentType: 'digit',
214
- maxLength: 2
215
- },
216
- mm: 'minutes',
217
- // Seconds
218
- s: {
219
- sectionType: 'seconds',
220
- contentType: 'digit',
221
- maxLength: 2
222
- },
223
- ss: 'seconds'
224
- };
225
- const defaultFormats = {
226
- year: 'yyyy',
227
- month: 'LLLL',
228
- monthShort: 'MMM',
229
- dayOfMonth: 'd',
230
- weekday: 'EEEE',
231
- weekdayShort: 'EEEEEE',
232
- hours24h: 'HH',
233
- hours12h: 'hh',
234
- meridiem: 'aa',
235
- minutes: 'mm',
236
- seconds: 'ss',
237
- fullDate: 'PP',
238
- fullDateWithWeekday: 'PPPP',
239
- keyboardDate: 'P',
240
- shortDate: 'MMM d',
241
- normalDate: 'd MMMM',
242
- normalDateWithWeekday: 'EEE, MMM d',
243
- monthAndYear: 'LLLL yyyy',
244
- monthAndDate: 'MMMM d',
245
- fullTime: 'p',
246
- fullTime12h: 'hh:mm aa',
247
- fullTime24h: 'HH:mm',
248
- fullDateTime: 'PP p',
249
- fullDateTime12h: 'PP hh:mm aa',
250
- fullDateTime24h: 'PP HH:mm',
251
- keyboardDateTime: 'P p',
252
- keyboardDateTime12h: 'P hh:mm aa',
253
- keyboardDateTime24h: 'P HH:mm'
254
- };
255
-
59
+ import { AdapterDateFnsBase } from '../AdapterDateFnsBase';
256
60
  /**
257
61
  * Based on `@date-io/date-fns`
258
62
  *
@@ -278,42 +82,19 @@ const defaultFormats = {
278
82
  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
279
83
  * SOFTWARE.
280
84
  */
281
- export class AdapterDateFns {
85
+ export class AdapterDateFns extends AdapterDateFnsBase {
282
86
  constructor({
283
- locale: _locale,
87
+ locale,
284
88
  formats
285
89
  } = {}) {
286
- this.isMUIAdapter = true;
287
- this.isTimezoneCompatible = false;
288
- this.lib = 'date-fns';
289
- this.locale = void 0;
290
- this.formats = void 0;
291
- this.formatTokenMap = formatTokenMap;
292
- this.escapedCharacters = {
293
- start: "'",
294
- end: "'"
295
- };
296
- this.date = value => {
297
- if (typeof value === 'undefined') {
298
- return new Date();
299
- }
300
- if (value === null) {
301
- return null;
302
- }
303
- return new Date(value);
304
- };
305
- this.dateWithTimezone = value => {
306
- return this.date(value);
307
- };
308
- this.getTimezone = () => {
309
- return 'default';
310
- };
311
- this.setTimezone = value => {
312
- return value;
313
- };
314
- this.toJsDate = value => {
315
- return value;
316
- };
90
+ if (typeof addDays !== 'function') {
91
+ throw new Error(['MUI: The `date-fns` package v3.x is not compatible with this adapter.', 'Please, install v2.x of the package or use the `AdapterDateFnsV3` instead.'].join('\n'));
92
+ }
93
+ super({
94
+ locale: locale ?? defaultLocale,
95
+ formats,
96
+ longFormatters
97
+ });
317
98
  this.parseISO = isoString => {
318
99
  return parseISO(isoString);
319
100
  };
@@ -330,39 +111,6 @@ export class AdapterDateFns {
330
111
  locale: this.locale
331
112
  });
332
113
  };
333
- this.getCurrentLocaleCode = () => {
334
- return this.locale?.code || 'en-US';
335
- };
336
- // Note: date-fns input types are more lenient than this adapter, so we need to expose our more
337
- // strict signature and delegate to the more lenient signature. Otherwise, we have downstream type errors upon usage.
338
- this.is12HourCycleInCurrentLocale = () => {
339
- if (this.locale) {
340
- return /a/.test(this.locale.formatLong.time());
341
- }
342
-
343
- // By default, date-fns is using en-US locale with am/pm enabled
344
- return true;
345
- };
346
- this.expandFormat = format => {
347
- const longFormatRegexp = /P+p+|P+|p+|''|'(''|[^'])+('|$)|./g;
348
-
349
- // @see https://github.com/date-fns/date-fns/blob/master/src/format/index.js#L31
350
- return format.match(longFormatRegexp).map(token => {
351
- const firstCharacter = token[0];
352
- if (firstCharacter === 'p' || firstCharacter === 'P') {
353
- const longFormatter = longFormatters[firstCharacter];
354
- const locale = this.locale || defaultLocale;
355
- return longFormatter(token, locale.formatLong, {});
356
- }
357
- return token;
358
- }).join('');
359
- };
360
- this.getFormatHelperText = format => {
361
- return this.expandFormat(format).replace(/(aaa|aa|a)/g, '(a|p)m').toLocaleLowerCase();
362
- };
363
- this.isNull = value => {
364
- return value === null;
365
- };
366
114
  this.isValid = value => {
367
115
  return isValid(this.date(value));
368
116
  };
@@ -374,9 +122,6 @@ export class AdapterDateFns {
374
122
  locale: this.locale
375
123
  });
376
124
  };
377
- this.formatNumber = numberToFormat => {
378
- return numberToFormat;
379
- };
380
125
  this.getDiff = (value, comparing, unit) => {
381
126
  switch (unit) {
382
127
  case 'years':
@@ -601,10 +346,5 @@ export class AdapterDateFns {
601
346
  }
602
347
  return years;
603
348
  };
604
- this.getMeridiemText = ampm => {
605
- return ampm === 'am' ? 'AM' : 'PM';
606
- };
607
- this.locale = _locale;
608
- this.formats = _extends({}, defaultFormats, formats);
609
349
  }
610
350
  }
@@ -0,0 +1,307 @@
1
+ import _extends from "@babel/runtime/helpers/esm/extends";
2
+ /* eslint-disable class-methods-use-this */
3
+
4
+ const formatTokenMap = {
5
+ // Year
6
+ y: {
7
+ sectionType: 'year',
8
+ contentType: 'digit',
9
+ maxLength: 4
10
+ },
11
+ yy: 'year',
12
+ yyy: {
13
+ sectionType: 'year',
14
+ contentType: 'digit',
15
+ maxLength: 4
16
+ },
17
+ yyyy: 'year',
18
+ // Month
19
+ M: {
20
+ sectionType: 'month',
21
+ contentType: 'digit',
22
+ maxLength: 2
23
+ },
24
+ MM: 'month',
25
+ MMMM: {
26
+ sectionType: 'month',
27
+ contentType: 'letter'
28
+ },
29
+ MMM: {
30
+ sectionType: 'month',
31
+ contentType: 'letter'
32
+ },
33
+ L: {
34
+ sectionType: 'month',
35
+ contentType: 'digit',
36
+ maxLength: 2
37
+ },
38
+ LL: 'month',
39
+ LLL: {
40
+ sectionType: 'month',
41
+ contentType: 'letter'
42
+ },
43
+ LLLL: {
44
+ sectionType: 'month',
45
+ contentType: 'letter'
46
+ },
47
+ // Day of the month
48
+ d: {
49
+ sectionType: 'day',
50
+ contentType: 'digit',
51
+ maxLength: 2
52
+ },
53
+ dd: 'day',
54
+ do: {
55
+ sectionType: 'day',
56
+ contentType: 'digit-with-letter'
57
+ },
58
+ // Day of the week
59
+ E: {
60
+ sectionType: 'weekDay',
61
+ contentType: 'letter'
62
+ },
63
+ EE: {
64
+ sectionType: 'weekDay',
65
+ contentType: 'letter'
66
+ },
67
+ EEE: {
68
+ sectionType: 'weekDay',
69
+ contentType: 'letter'
70
+ },
71
+ EEEE: {
72
+ sectionType: 'weekDay',
73
+ contentType: 'letter'
74
+ },
75
+ EEEEE: {
76
+ sectionType: 'weekDay',
77
+ contentType: 'letter'
78
+ },
79
+ i: {
80
+ sectionType: 'weekDay',
81
+ contentType: 'digit',
82
+ maxLength: 1
83
+ },
84
+ ii: 'weekDay',
85
+ iii: {
86
+ sectionType: 'weekDay',
87
+ contentType: 'letter'
88
+ },
89
+ iiii: {
90
+ sectionType: 'weekDay',
91
+ contentType: 'letter'
92
+ },
93
+ e: {
94
+ sectionType: 'weekDay',
95
+ contentType: 'digit',
96
+ maxLength: 1
97
+ },
98
+ ee: 'weekDay',
99
+ eee: {
100
+ sectionType: 'weekDay',
101
+ contentType: 'letter'
102
+ },
103
+ eeee: {
104
+ sectionType: 'weekDay',
105
+ contentType: 'letter'
106
+ },
107
+ eeeee: {
108
+ sectionType: 'weekDay',
109
+ contentType: 'letter'
110
+ },
111
+ eeeeee: {
112
+ sectionType: 'weekDay',
113
+ contentType: 'letter'
114
+ },
115
+ c: {
116
+ sectionType: 'weekDay',
117
+ contentType: 'digit',
118
+ maxLength: 1
119
+ },
120
+ cc: 'weekDay',
121
+ ccc: {
122
+ sectionType: 'weekDay',
123
+ contentType: 'letter'
124
+ },
125
+ cccc: {
126
+ sectionType: 'weekDay',
127
+ contentType: 'letter'
128
+ },
129
+ ccccc: {
130
+ sectionType: 'weekDay',
131
+ contentType: 'letter'
132
+ },
133
+ cccccc: {
134
+ sectionType: 'weekDay',
135
+ contentType: 'letter'
136
+ },
137
+ // Meridiem
138
+ a: 'meridiem',
139
+ aa: 'meridiem',
140
+ aaa: 'meridiem',
141
+ // Hours
142
+ H: {
143
+ sectionType: 'hours',
144
+ contentType: 'digit',
145
+ maxLength: 2
146
+ },
147
+ HH: 'hours',
148
+ h: {
149
+ sectionType: 'hours',
150
+ contentType: 'digit',
151
+ maxLength: 2
152
+ },
153
+ hh: 'hours',
154
+ // Minutes
155
+ m: {
156
+ sectionType: 'minutes',
157
+ contentType: 'digit',
158
+ maxLength: 2
159
+ },
160
+ mm: 'minutes',
161
+ // Seconds
162
+ s: {
163
+ sectionType: 'seconds',
164
+ contentType: 'digit',
165
+ maxLength: 2
166
+ },
167
+ ss: 'seconds'
168
+ };
169
+ const defaultFormats = {
170
+ year: 'yyyy',
171
+ month: 'LLLL',
172
+ monthShort: 'MMM',
173
+ dayOfMonth: 'd',
174
+ weekday: 'EEEE',
175
+ weekdayShort: 'EEEEEE',
176
+ hours24h: 'HH',
177
+ hours12h: 'hh',
178
+ meridiem: 'aa',
179
+ minutes: 'mm',
180
+ seconds: 'ss',
181
+ fullDate: 'PP',
182
+ fullDateWithWeekday: 'PPPP',
183
+ keyboardDate: 'P',
184
+ shortDate: 'MMM d',
185
+ normalDate: 'd MMMM',
186
+ normalDateWithWeekday: 'EEE, MMM d',
187
+ monthAndYear: 'LLLL yyyy',
188
+ monthAndDate: 'MMMM d',
189
+ fullTime: 'p',
190
+ fullTime12h: 'hh:mm aa',
191
+ fullTime24h: 'HH:mm',
192
+ fullDateTime: 'PP p',
193
+ fullDateTime12h: 'PP hh:mm aa',
194
+ fullDateTime24h: 'PP HH:mm',
195
+ keyboardDateTime: 'P p',
196
+ keyboardDateTime12h: 'P hh:mm aa',
197
+ keyboardDateTime24h: 'P HH:mm'
198
+ };
199
+ /**
200
+ * Based on `@date-io/date-fns`
201
+ *
202
+ * MIT License
203
+ *
204
+ * Copyright (c) 2017 Dmitriy Kovalenko
205
+ *
206
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
207
+ * of this software and associated documentation files (the "Software"), to deal
208
+ * in the Software without restriction, including without limitation the rights
209
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
210
+ * copies of the Software, and to permit persons to whom the Software is
211
+ * furnished to do so, subject to the following conditions:
212
+ *
213
+ * The above copyright notice and this permission notice shall be included in all
214
+ * copies or substantial portions of the Software.
215
+ *
216
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
217
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
218
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
219
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
220
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
221
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
222
+ * SOFTWARE.
223
+ */
224
+ export class AdapterDateFnsBase {
225
+ constructor(props) {
226
+ this.isMUIAdapter = true;
227
+ this.isTimezoneCompatible = false;
228
+ this.lib = 'date-fns';
229
+ this.locale = void 0;
230
+ this.formats = void 0;
231
+ this.formatTokenMap = formatTokenMap;
232
+ this.escapedCharacters = {
233
+ start: "'",
234
+ end: "'"
235
+ };
236
+ this.longFormatters = void 0;
237
+ this.date = value => {
238
+ if (typeof value === 'undefined') {
239
+ return new Date();
240
+ }
241
+ if (value === null) {
242
+ return null;
243
+ }
244
+ return new Date(value);
245
+ };
246
+ this.dateWithTimezone = value => {
247
+ return this.date(value);
248
+ };
249
+ this.getTimezone = () => {
250
+ return 'default';
251
+ };
252
+ this.setTimezone = value => {
253
+ return value;
254
+ };
255
+ this.toJsDate = value => {
256
+ return value;
257
+ };
258
+ this.getCurrentLocaleCode = () => {
259
+ return this.locale?.code || 'en-US';
260
+ };
261
+ // Note: date-fns input types are more lenient than this adapter, so we need to expose our more
262
+ // strict signature and delegate to the more lenient signature. Otherwise, we have downstream type errors upon usage.
263
+ this.is12HourCycleInCurrentLocale = () => {
264
+ if (this.locale) {
265
+ return /a/.test(this.locale.formatLong.time({
266
+ width: 'short'
267
+ }));
268
+ }
269
+
270
+ // By default, date-fns is using en-US locale with am/pm enabled
271
+ return true;
272
+ };
273
+ this.expandFormat = format => {
274
+ const longFormatRegexp = /P+p+|P+|p+|''|'(''|[^'])+('|$)|./g;
275
+
276
+ // @see https://github.com/date-fns/date-fns/blob/master/src/format/index.js#L31
277
+ return format.match(longFormatRegexp).map(token => {
278
+ const firstCharacter = token[0];
279
+ if (firstCharacter === 'p' || firstCharacter === 'P') {
280
+ const longFormatter = this.longFormatters[firstCharacter];
281
+ return longFormatter(token, this.locale.formatLong);
282
+ }
283
+ return token;
284
+ }).join('');
285
+ };
286
+ this.getFormatHelperText = format => {
287
+ return this.expandFormat(format).replace(/(aaa|aa|a)/g, '(a|p)m').toLocaleLowerCase();
288
+ };
289
+ this.isNull = value => {
290
+ return value === null;
291
+ };
292
+ this.formatNumber = numberToFormat => {
293
+ return numberToFormat;
294
+ };
295
+ this.getMeridiemText = ampm => {
296
+ return ampm === 'am' ? 'AM' : 'PM';
297
+ };
298
+ const {
299
+ locale,
300
+ formats,
301
+ longFormatters
302
+ } = props;
303
+ this.locale = locale;
304
+ this.formats = _extends({}, defaultFormats, formats);
305
+ this.longFormatters = longFormatters;
306
+ }
307
+ }
@@ -0,0 +1 @@
1
+ export { AdapterDateFnsBase } from './AdapterDateFnsBase';