@mui/x-date-pickers 6.18.6 → 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/AdapterLuxon/AdapterLuxon.d.ts +32 -32
- package/CHANGELOG.md +85 -1
- package/DateCalendar/DateCalendar.js +6 -4
- package/DateCalendar/DateCalendar.types.d.ts +0 -8
- package/DigitalClock/DigitalClock.js +3 -2
- package/MultiSectionDigitalClock/MultiSectionDigitalClock.js +9 -13
- package/MultiSectionDigitalClock/MultiSectionDigitalClockSection.js +8 -12
- package/TimeClock/TimeClock.js +3 -2
- package/hooks/useClearableField.d.ts +1 -1
- package/hooks/useClearableField.js +3 -3
- package/index.js +1 -1
- package/internals/hooks/useViews.d.ts +4 -4
- package/internals/hooks/useViews.js +13 -13
- package/internals/models/helpers.d.ts +1 -0
- package/internals/models/props/clock.d.ts +0 -9
- 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/DateCalendar/DateCalendar.js +6 -4
- package/legacy/DigitalClock/DigitalClock.js +3 -2
- package/legacy/MultiSectionDigitalClock/MultiSectionDigitalClock.js +9 -13
- package/legacy/MultiSectionDigitalClock/MultiSectionDigitalClockSection.js +8 -12
- package/legacy/TimeClock/TimeClock.js +3 -2
- package/legacy/hooks/useClearableField.js +3 -3
- package/legacy/index.js +1 -1
- package/legacy/internals/hooks/useViews.js +13 -13
- 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/DateCalendar/DateCalendar.js +6 -4
- package/modern/DigitalClock/DigitalClock.js +3 -2
- package/modern/MultiSectionDigitalClock/MultiSectionDigitalClock.js +9 -13
- package/modern/MultiSectionDigitalClock/MultiSectionDigitalClockSection.js +8 -12
- package/modern/TimeClock/TimeClock.js +3 -2
- package/modern/hooks/useClearableField.js +3 -3
- package/modern/index.js +1 -1
- package/modern/internals/hooks/useViews.js +13 -13
- 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/DateCalendar/DateCalendar.js +6 -4
- package/node/DigitalClock/DigitalClock.js +3 -2
- package/node/MultiSectionDigitalClock/MultiSectionDigitalClock.js +9 -13
- package/node/MultiSectionDigitalClock/MultiSectionDigitalClockSection.js +8 -12
- package/node/TimeClock/TimeClock.js +3 -2
- package/node/hooks/useClearableField.js +3 -3
- package/node/index.js +1 -1
- package/node/internals/hooks/useViews.js +13 -13
- package/node/locales/index.js +11 -0
- package/package.json +2 -2
|
@@ -259,9 +259,9 @@ export var DateCalendar = /*#__PURE__*/React.forwardRef(function DateCalendar(in
|
|
|
259
259
|
var handleSelectedDayChange = useEventCallback(function (day) {
|
|
260
260
|
if (day) {
|
|
261
261
|
// If there is a date already selected, then we want to keep its time
|
|
262
|
-
return handleValueChange(mergeDateAndTime(utils, day, value != null ? value : referenceDate), 'finish');
|
|
262
|
+
return handleValueChange(mergeDateAndTime(utils, day, value != null ? value : referenceDate), 'finish', view);
|
|
263
263
|
}
|
|
264
|
-
return handleValueChange(day, 'finish');
|
|
264
|
+
return handleValueChange(day, 'finish', view);
|
|
265
265
|
});
|
|
266
266
|
React.useEffect(function () {
|
|
267
267
|
if (value != null && utils.isValid(value)) {
|
|
@@ -458,9 +458,11 @@ process.env.NODE_ENV !== "production" ? DateCalendar.propTypes = {
|
|
|
458
458
|
monthsPerRow: PropTypes.oneOf([3, 4]),
|
|
459
459
|
/**
|
|
460
460
|
* Callback fired when the value changes.
|
|
461
|
-
* @template
|
|
462
|
-
* @
|
|
461
|
+
* @template TValue The value type. Will be either the same type as `value` or `null`. Can be in `[start, end]` format in case of range value.
|
|
462
|
+
* @template TView The view type. Will be one of date or time views.
|
|
463
|
+
* @param {TValue} value The new value.
|
|
463
464
|
* @param {PickerSelectionState | undefined} selectionState Indicates if the date selection is complete.
|
|
465
|
+
* @param {TView | undefined} selectedView Indicates the view in which the selection has been made.
|
|
464
466
|
*/
|
|
465
467
|
onChange: PropTypes.func,
|
|
466
468
|
/**
|
|
@@ -357,8 +357,9 @@ process.env.NODE_ENV !== "production" ? DigitalClock.propTypes = {
|
|
|
357
357
|
minutesStep: PropTypes.number,
|
|
358
358
|
/**
|
|
359
359
|
* Callback fired when the value changes.
|
|
360
|
-
* @template
|
|
361
|
-
* @
|
|
360
|
+
* @template TValue The value type. Will be either the same type as `value` or `null`. Can be in `[start, end]` format in case of range value.
|
|
361
|
+
* @template TView The view type. Will be one of date or time views.
|
|
362
|
+
* @param {TValue} value The new value.
|
|
362
363
|
* @param {PickerSelectionState | undefined} selectionState Indicates if the date selection is complete.
|
|
363
364
|
* @param {TView | undefined} selectedView Indicates the view in which the selection has been made.
|
|
364
365
|
*/
|
|
@@ -143,10 +143,10 @@ export var MultiSectionDigitalClock = /*#__PURE__*/React.forwardRef(function Mul
|
|
|
143
143
|
onFocusedViewChange: onFocusedViewChange
|
|
144
144
|
}),
|
|
145
145
|
view = _useViews.view,
|
|
146
|
-
|
|
146
|
+
setValueAndGoToNextView = _useViews.setValueAndGoToNextView,
|
|
147
147
|
focusedView = _useViews.focusedView;
|
|
148
148
|
var handleMeridiemValueChange = useEventCallback(function (newValue) {
|
|
149
|
-
|
|
149
|
+
setValueAndGoToNextView(newValue, 'finish', 'meridiem');
|
|
150
150
|
});
|
|
151
151
|
var _useMeridiemMode = useMeridiemMode(valueOrReferenceDate, ampm, handleMeridiemValueChange, 'finish'),
|
|
152
152
|
meridiemMode = _useMeridiemMode.meridiemMode,
|
|
@@ -229,11 +229,6 @@ export var MultiSectionDigitalClock = /*#__PURE__*/React.forwardRef(function Mul
|
|
|
229
229
|
throw new Error('not supported');
|
|
230
230
|
}
|
|
231
231
|
}, [ampm, valueOrReferenceDate, disableIgnoringDatePartForTimeValidation, maxTime, meridiemMode, minTime, minutesStep, shouldDisableClock, shouldDisableTime, utils, disableFuture, disablePast, now, views]);
|
|
232
|
-
var handleSectionChange = useEventCallback(function (sectionView, newValue) {
|
|
233
|
-
var viewIndex = views.indexOf(sectionView);
|
|
234
|
-
var nextView = views[viewIndex + 1];
|
|
235
|
-
setValueAndGoToView(newValue, nextView, sectionView);
|
|
236
|
-
});
|
|
237
232
|
var buildViewProps = React.useCallback(function (viewToBuild) {
|
|
238
233
|
switch (viewToBuild) {
|
|
239
234
|
case 'hours':
|
|
@@ -241,7 +236,7 @@ export var MultiSectionDigitalClock = /*#__PURE__*/React.forwardRef(function Mul
|
|
|
241
236
|
return {
|
|
242
237
|
onChange: function onChange(hours) {
|
|
243
238
|
var valueWithMeridiem = convertValueToMeridiem(hours, meridiemMode, ampm);
|
|
244
|
-
|
|
239
|
+
setValueAndGoToNextView(utils.setHours(valueOrReferenceDate, valueWithMeridiem), 'finish', 'hours');
|
|
245
240
|
},
|
|
246
241
|
items: getHourSectionOptions({
|
|
247
242
|
now: now,
|
|
@@ -260,7 +255,7 @@ export var MultiSectionDigitalClock = /*#__PURE__*/React.forwardRef(function Mul
|
|
|
260
255
|
{
|
|
261
256
|
return {
|
|
262
257
|
onChange: function onChange(minutes) {
|
|
263
|
-
|
|
258
|
+
setValueAndGoToNextView(utils.setMinutes(valueOrReferenceDate, minutes), 'finish', 'minutes');
|
|
264
259
|
},
|
|
265
260
|
items: getTimeSectionOptions({
|
|
266
261
|
value: utils.getMinutes(valueOrReferenceDate),
|
|
@@ -281,7 +276,7 @@ export var MultiSectionDigitalClock = /*#__PURE__*/React.forwardRef(function Mul
|
|
|
281
276
|
{
|
|
282
277
|
return {
|
|
283
278
|
onChange: function onChange(seconds) {
|
|
284
|
-
|
|
279
|
+
setValueAndGoToNextView(utils.setSeconds(valueOrReferenceDate, seconds), 'finish', 'seconds');
|
|
285
280
|
},
|
|
286
281
|
items: getTimeSectionOptions({
|
|
287
282
|
value: utils.getSeconds(valueOrReferenceDate),
|
|
@@ -324,7 +319,7 @@ export var MultiSectionDigitalClock = /*#__PURE__*/React.forwardRef(function Mul
|
|
|
324
319
|
default:
|
|
325
320
|
throw new Error("Unknown view: ".concat(viewToBuild, " found."));
|
|
326
321
|
}
|
|
327
|
-
}, [now, value, ampm, utils, timeSteps.hours, timeSteps.minutes, timeSteps.seconds, localeText.hoursClockNumberText, localeText.minutesClockNumberText, localeText.secondsClockNumberText, meridiemMode,
|
|
322
|
+
}, [now, value, ampm, utils, timeSteps.hours, timeSteps.minutes, timeSteps.seconds, localeText.hoursClockNumberText, localeText.minutesClockNumberText, localeText.secondsClockNumberText, meridiemMode, setValueAndGoToNextView, valueOrReferenceDate, disabled, isTimeDisabled, handleMeridiemChange]);
|
|
328
323
|
var viewTimeOptions = React.useMemo(function () {
|
|
329
324
|
return views.reduce(function (result, currentView) {
|
|
330
325
|
return _extends({}, result, _defineProperty({}, currentView, buildViewProps(currentView)));
|
|
@@ -437,8 +432,9 @@ process.env.NODE_ENV !== "production" ? MultiSectionDigitalClock.propTypes = {
|
|
|
437
432
|
minutesStep: PropTypes.number,
|
|
438
433
|
/**
|
|
439
434
|
* Callback fired when the value changes.
|
|
440
|
-
* @template
|
|
441
|
-
* @
|
|
435
|
+
* @template TValue The value type. Will be either the same type as `value` or `null`. Can be in `[start, end]` format in case of range value.
|
|
436
|
+
* @template TView The view type. Will be one of date or time views.
|
|
437
|
+
* @param {TValue} value The new value.
|
|
442
438
|
* @param {PickerSelectionState | undefined} selectionState Indicates if the date selection is complete.
|
|
443
439
|
* @param {TView | undefined} selectedView Indicates the view in which the selection has been made.
|
|
444
440
|
*/
|
|
@@ -93,7 +93,7 @@ export var MultiSectionDigitalClockSection = /*#__PURE__*/React.forwardRef(funct
|
|
|
93
93
|
var _slots$digitalClockSe;
|
|
94
94
|
var containerRef = React.useRef(null);
|
|
95
95
|
var handleRef = useForkRef(ref, containerRef);
|
|
96
|
-
var
|
|
96
|
+
var previousActive = React.useRef(null);
|
|
97
97
|
var props = useThemeProps({
|
|
98
98
|
props: inProps,
|
|
99
99
|
name: 'MuiMultiSectionDigitalClockSection'
|
|
@@ -120,19 +120,15 @@ export var MultiSectionDigitalClockSection = /*#__PURE__*/React.forwardRef(funct
|
|
|
120
120
|
if (containerRef.current === null) {
|
|
121
121
|
return;
|
|
122
122
|
}
|
|
123
|
-
var
|
|
124
|
-
if (
|
|
125
|
-
|
|
126
|
-
if (previousSelected.current !== selectedItem) {
|
|
127
|
-
previousSelected.current = selectedItem;
|
|
128
|
-
}
|
|
129
|
-
return;
|
|
123
|
+
var activeItem = containerRef.current.querySelector('[role="option"][aria-selected="true"]');
|
|
124
|
+
if (active && autoFocus && activeItem) {
|
|
125
|
+
activeItem.focus();
|
|
130
126
|
}
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
selectedItem.focus();
|
|
127
|
+
if (!activeItem || previousActive.current === activeItem) {
|
|
128
|
+
return;
|
|
134
129
|
}
|
|
135
|
-
|
|
130
|
+
previousActive.current = activeItem;
|
|
131
|
+
var offsetTop = activeItem.offsetTop;
|
|
136
132
|
|
|
137
133
|
// Subtracting the 4px of extra margin intended for the first visible section item
|
|
138
134
|
containerRef.current.scrollTop = offsetTop - 4;
|
|
@@ -416,8 +416,9 @@ process.env.NODE_ENV !== "production" ? TimeClock.propTypes = {
|
|
|
416
416
|
minutesStep: PropTypes.number,
|
|
417
417
|
/**
|
|
418
418
|
* Callback fired when the value changes.
|
|
419
|
-
* @template
|
|
420
|
-
* @
|
|
419
|
+
* @template TValue The value type. Will be either the same type as `value` or `null`. Can be in `[start, end]` format in case of range value.
|
|
420
|
+
* @template TView The view type. Will be one of date or time views.
|
|
421
|
+
* @param {TValue} value The new value.
|
|
421
422
|
* @param {PickerSelectionState | undefined} selectionState Indicates if the date selection is complete.
|
|
422
423
|
* @param {TView | undefined} selectedView Indicates the view in which the selection has been made.
|
|
423
424
|
*/
|
|
@@ -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
|
@@ -75,11 +75,12 @@ export function useViews(_ref) {
|
|
|
75
75
|
onFocusedViewChange == null || onFocusedViewChange(viewToFocus, hasFocus);
|
|
76
76
|
});
|
|
77
77
|
var handleChangeView = useEventCallback(function (newView) {
|
|
78
|
+
// always keep the focused view in sync
|
|
79
|
+
handleFocusedViewChange(newView, true);
|
|
78
80
|
if (newView === view) {
|
|
79
81
|
return;
|
|
80
82
|
}
|
|
81
83
|
setView(newView);
|
|
82
|
-
handleFocusedViewChange(newView, true);
|
|
83
84
|
if (onViewChange) {
|
|
84
85
|
onViewChange(newView);
|
|
85
86
|
}
|
|
@@ -88,7 +89,6 @@ export function useViews(_ref) {
|
|
|
88
89
|
if (nextView) {
|
|
89
90
|
handleChangeView(nextView);
|
|
90
91
|
}
|
|
91
|
-
handleFocusedViewChange(nextView, true);
|
|
92
92
|
});
|
|
93
93
|
var setValueAndGoToNextView = useEventCallback(function (value, currentViewSelectionState, selectedView) {
|
|
94
94
|
var isSelectionFinishedOnCurrentView = currentViewSelectionState === 'finish';
|
|
@@ -97,18 +97,19 @@ export function useViews(_ref) {
|
|
|
97
97
|
// but we it's not the final view given all `views` -> overall selection state should be `partial`.
|
|
98
98
|
views.indexOf(selectedView) < views.length - 1 : Boolean(nextView);
|
|
99
99
|
var globalSelectionState = isSelectionFinishedOnCurrentView && hasMoreViews ? 'partial' : currentViewSelectionState;
|
|
100
|
-
onChange(value, globalSelectionState);
|
|
101
|
-
if
|
|
100
|
+
onChange(value, globalSelectionState, selectedView);
|
|
101
|
+
// Detects if the selected view is not the active one.
|
|
102
|
+
// Can happen if multiple views are displayed, like in `DesktopDateTimePicker` or `MultiSectionDigitalClock`.
|
|
103
|
+
if (selectedView && selectedView !== view) {
|
|
104
|
+
var nextViewAfterSelected = views[views.indexOf(selectedView) + 1];
|
|
105
|
+
if (nextViewAfterSelected) {
|
|
106
|
+
// move to next view after the selected one
|
|
107
|
+
handleChangeView(nextViewAfterSelected);
|
|
108
|
+
}
|
|
109
|
+
} else if (isSelectionFinishedOnCurrentView) {
|
|
102
110
|
goToNextView();
|
|
103
111
|
}
|
|
104
112
|
});
|
|
105
|
-
var setValueAndGoToView = useEventCallback(function (value, newView, selectedView) {
|
|
106
|
-
onChange(value, newView ? 'partial' : 'finish', selectedView);
|
|
107
|
-
if (newView) {
|
|
108
|
-
handleChangeView(newView);
|
|
109
|
-
handleFocusedViewChange(newView, true);
|
|
110
|
-
}
|
|
111
|
-
});
|
|
112
113
|
return {
|
|
113
114
|
view: view,
|
|
114
115
|
setView: handleChangeView,
|
|
@@ -119,7 +120,6 @@ export function useViews(_ref) {
|
|
|
119
120
|
// Always return up to date default view instead of the initial one (i.e. defaultView.current)
|
|
120
121
|
defaultView: views.includes(openTo) ? openTo : views[0],
|
|
121
122
|
goToNextView: goToNextView,
|
|
122
|
-
setValueAndGoToNextView: setValueAndGoToNextView
|
|
123
|
-
setValueAndGoToView: setValueAndGoToView
|
|
123
|
+
setValueAndGoToNextView: setValueAndGoToNextView
|
|
124
124
|
};
|
|
125
125
|
}
|
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
|
}
|