@mui/x-date-pickers 7.0.0-alpha.6 → 7.0.0-alpha.8

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