@mui/x-date-pickers 6.18.7 → 6.19.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.
- package/AdapterDateFns/AdapterDateFns.d.ts +3 -24
- package/AdapterDateFns/AdapterDateFns.js +11 -272
- package/AdapterDateFnsBase/AdapterDateFnsBase.d.ts +65 -0
- package/AdapterDateFnsBase/AdapterDateFnsBase.js +308 -0
- package/AdapterDateFnsBase/index.d.ts +1 -0
- package/AdapterDateFnsBase/index.js +1 -0
- package/AdapterDateFnsBase/package.json +6 -0
- package/AdapterDateFnsV3/AdapterDateFnsV3.d.ts +88 -0
- package/AdapterDateFnsV3/AdapterDateFnsV3.js +357 -0
- package/AdapterDateFnsV3/index.d.ts +1 -0
- package/AdapterDateFnsV3/index.js +1 -0
- package/AdapterDateFnsV3/package.json +6 -0
- package/CHANGELOG.md +42 -0
- package/hooks/useClearableField.d.ts +1 -1
- package/hooks/useClearableField.js +3 -3
- package/index.js +1 -1
- package/internals/models/helpers.d.ts +1 -0
- package/legacy/AdapterDateFns/AdapterDateFns.js +278 -528
- package/legacy/AdapterDateFnsBase/AdapterDateFnsBase.js +308 -0
- package/legacy/AdapterDateFnsBase/index.js +1 -0
- package/legacy/AdapterDateFnsV3/AdapterDateFnsV3.js +376 -0
- package/legacy/AdapterDateFnsV3/index.js +1 -0
- package/legacy/hooks/useClearableField.js +3 -3
- package/legacy/index.js +1 -1
- package/legacy/locales/index.js +1 -0
- package/locales/index.d.ts +1 -0
- package/locales/index.js +1 -0
- package/modern/AdapterDateFns/AdapterDateFns.js +11 -271
- package/modern/AdapterDateFnsBase/AdapterDateFnsBase.js +307 -0
- package/modern/AdapterDateFnsBase/index.js +1 -0
- package/modern/AdapterDateFnsV3/AdapterDateFnsV3.js +357 -0
- package/modern/AdapterDateFnsV3/index.js +1 -0
- package/modern/hooks/useClearableField.js +3 -3
- package/modern/index.js +1 -1
- package/modern/locales/index.js +1 -0
- package/node/AdapterDateFns/AdapterDateFns.js +11 -271
- package/node/AdapterDateFnsBase/AdapterDateFnsBase.js +315 -0
- package/node/AdapterDateFnsBase/index.js +12 -0
- package/node/AdapterDateFnsV3/AdapterDateFnsV3.js +366 -0
- package/node/AdapterDateFnsV3/index.js +12 -0
- package/node/hooks/useClearableField.js +3 -3
- package/node/index.js +1 -1
- package/node/locales/index.js +11 -0
- package/package.json +2 -2
|
@@ -41,8 +41,8 @@ export var useClearableField = function useClearableField(_ref) {
|
|
|
41
41
|
ownerState: {}
|
|
42
42
|
});
|
|
43
43
|
var InputProps = _extends({}, ForwardedInputProps, {
|
|
44
|
-
endAdornment:
|
|
45
|
-
children: [/*#__PURE__*/_jsx(InputAdornment, {
|
|
44
|
+
endAdornment: /*#__PURE__*/_jsxs(React.Fragment, {
|
|
45
|
+
children: [clearable && /*#__PURE__*/_jsx(InputAdornment, {
|
|
46
46
|
position: "end",
|
|
47
47
|
sx: {
|
|
48
48
|
marginRight: ForwardedInputProps != null && ForwardedInputProps.endAdornment ? -1 : -1.5
|
|
@@ -54,7 +54,7 @@ export var useClearableField = function useClearableField(_ref) {
|
|
|
54
54
|
}, endClearIconProps))
|
|
55
55
|
}))
|
|
56
56
|
}), ForwardedInputProps == null ? void 0 : ForwardedInputProps.endAdornment]
|
|
57
|
-
})
|
|
57
|
+
})
|
|
58
58
|
});
|
|
59
59
|
var fieldProps = _extends({}, forwardedFieldProps, {
|
|
60
60
|
sx: [{
|
package/legacy/index.js
CHANGED
package/legacy/locales/index.js
CHANGED
package/locales/index.d.ts
CHANGED
package/locales/index.js
CHANGED
|
@@ -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
|
-
|
|
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
|
|
87
|
+
locale,
|
|
284
88
|
formats
|
|
285
89
|
} = {}) {
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
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';
|