@mui/x-date-pickers 7.3.2 → 7.5.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 +5 -0
- package/AdapterDateFnsBase/AdapterDateFnsBase.d.ts +1 -5
- package/AdapterDateFnsBase/AdapterDateFnsBase.js +4 -2
- package/AdapterDateFnsJalali/AdapterDateFnsJalali.d.ts +3 -20
- package/AdapterDateFnsJalali/AdapterDateFnsJalali.js +14 -224
- package/AdapterDateFnsJalaliV3/AdapterDateFnsJalaliV3.d.ts +87 -0
- package/AdapterDateFnsJalaliV3/AdapterDateFnsJalaliV3.js +332 -0
- package/AdapterDateFnsJalaliV3/index.d.ts +1 -0
- package/AdapterDateFnsJalaliV3/index.js +1 -0
- package/AdapterDateFnsJalaliV3/package.json +6 -0
- package/AdapterDateFnsV3/AdapterDateFnsV3.d.ts +5 -0
- package/AdapterDateFnsV3/AdapterDateFnsV3.js +0 -1
- package/AdapterMomentJalaali/AdapterMomentJalaali.js +2 -6
- package/CHANGELOG.md +160 -2
- package/DateCalendar/DateCalendar.js +5 -4
- package/PickersLayout/usePickerLayout.js +6 -7
- package/PickersShortcuts/PickersShortcuts.d.ts +5 -0
- package/PickersShortcuts/PickersShortcuts.js +4 -3
- package/index.js +1 -1
- package/internals/components/PickersModalDialog.d.ts +2 -2
- package/internals/demo/DemoContainer.js +1 -1
- package/internals/hooks/useField/useField.js +0 -5
- package/internals/hooks/useField/useFieldV6TextField.js +1 -1
- package/internals/hooks/useField/useFieldV7TextField.js +5 -0
- package/internals/hooks/usePicker/usePickerViews.js +1 -0
- package/modern/AdapterDateFnsBase/AdapterDateFnsBase.js +4 -2
- package/modern/AdapterDateFnsJalali/AdapterDateFnsJalali.js +14 -224
- package/modern/AdapterDateFnsJalaliV3/AdapterDateFnsJalaliV3.js +332 -0
- package/modern/AdapterDateFnsJalaliV3/index.js +1 -0
- package/modern/AdapterDateFnsV3/AdapterDateFnsV3.js +0 -1
- package/modern/AdapterMomentJalaali/AdapterMomentJalaali.js +2 -6
- package/modern/DateCalendar/DateCalendar.js +5 -4
- package/modern/PickersLayout/usePickerLayout.js +6 -7
- package/modern/PickersShortcuts/PickersShortcuts.js +4 -3
- package/modern/index.js +1 -1
- package/modern/internals/demo/DemoContainer.js +1 -1
- package/modern/internals/hooks/useField/useField.js +0 -5
- package/modern/internals/hooks/useField/useFieldV6TextField.js +1 -1
- package/modern/internals/hooks/useField/useFieldV7TextField.js +5 -0
- package/modern/internals/hooks/usePicker/usePickerViews.js +1 -0
- package/node/AdapterDateFnsBase/AdapterDateFnsBase.js +4 -2
- package/node/AdapterDateFnsJalali/AdapterDateFnsJalali.js +14 -224
- package/node/AdapterDateFnsJalaliV3/AdapterDateFnsJalaliV3.js +341 -0
- package/node/AdapterDateFnsJalaliV3/index.js +12 -0
- package/node/AdapterMomentJalaali/AdapterMomentJalaali.js +2 -6
- package/node/DateCalendar/DateCalendar.js +5 -4
- package/node/PickersLayout/usePickerLayout.js +6 -7
- package/node/PickersShortcuts/PickersShortcuts.js +4 -3
- package/node/index.js +1 -1
- package/node/internals/demo/DemoContainer.js +1 -1
- package/node/internals/hooks/useField/useField.js +0 -5
- package/node/internals/hooks/useField/useFieldV6TextField.js +1 -1
- package/node/internals/hooks/useField/useFieldV7TextField.js +5 -0
- package/node/internals/hooks/usePicker/usePickerViews.js +1 -0
- package/package.json +4 -4
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
2
|
import { DialogProps as MuiDialogProps } from '@mui/material/Dialog';
|
|
3
|
-
import { PaperProps as MuiPaperProps } from '@mui/material/Paper
|
|
4
|
-
import { TransitionProps as MuiTransitionProps } from '@mui/material/transitions
|
|
3
|
+
import { PaperProps as MuiPaperProps } from '@mui/material/Paper';
|
|
4
|
+
import { TransitionProps as MuiTransitionProps } from '@mui/material/transitions';
|
|
5
5
|
import { UsePickerValueActions } from '../hooks/usePicker/usePickerValue.types';
|
|
6
6
|
export interface PickersModalDialogSlots {
|
|
7
7
|
/**
|
|
@@ -3,7 +3,7 @@ import * as React from 'react';
|
|
|
3
3
|
import Stack, { stackClasses } from '@mui/material/Stack';
|
|
4
4
|
import Typography from '@mui/material/Typography';
|
|
5
5
|
import { textFieldClasses } from '@mui/material/TextField';
|
|
6
|
-
import { pickersTextFieldClasses } from '
|
|
6
|
+
import { pickersTextFieldClasses } from '../../PickersTextField';
|
|
7
7
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
8
8
|
const getChildTypeFromChildName = childName => {
|
|
9
9
|
if (childName.match(/^([A-Za-z]+)Range(Calendar|Clock)$/)) {
|
|
@@ -278,7 +278,7 @@ export const useFieldV6TextField = params => {
|
|
|
278
278
|
});
|
|
279
279
|
});
|
|
280
280
|
const placeholder = React.useMemo(() => {
|
|
281
|
-
if (inPlaceholder) {
|
|
281
|
+
if (inPlaceholder !== undefined) {
|
|
282
282
|
return inPlaceholder;
|
|
283
283
|
}
|
|
284
284
|
return fieldValueManager.getV6InputValueFromSections(getSectionsFromValue(valueManager.emptyValue), localizedDigits, isRTL);
|
|
@@ -282,6 +282,11 @@ export const useFieldV7TextField = params => {
|
|
|
282
282
|
revertDOMSectionChange(sectionIndex);
|
|
283
283
|
return;
|
|
284
284
|
}
|
|
285
|
+
const inputType = event.nativeEvent.inputType;
|
|
286
|
+
if (inputType === 'insertParagraph' || inputType === 'insertLineBreak') {
|
|
287
|
+
revertDOMSectionChange(sectionIndex);
|
|
288
|
+
return;
|
|
289
|
+
}
|
|
285
290
|
resetCharacterQuery();
|
|
286
291
|
clearActiveSection();
|
|
287
292
|
return;
|
|
@@ -100,6 +100,7 @@ export const usePickerViews = ({
|
|
|
100
100
|
if (currentViewMode === 'field' && open) {
|
|
101
101
|
onClose();
|
|
102
102
|
setTimeout(() => {
|
|
103
|
+
fieldRef?.current?.setSelectedSections(view);
|
|
103
104
|
// focusing the input before the range selection is done
|
|
104
105
|
// calling it outside of timeout results in an inconsistent behavior between Safari And Chrome
|
|
105
106
|
fieldRef?.current?.focusField(view);
|
|
@@ -220,7 +220,7 @@ export class AdapterDateFnsBase {
|
|
|
220
220
|
constructor(props) {
|
|
221
221
|
this.isMUIAdapter = true;
|
|
222
222
|
this.isTimezoneCompatible = false;
|
|
223
|
-
this.lib =
|
|
223
|
+
this.lib = void 0;
|
|
224
224
|
this.locale = void 0;
|
|
225
225
|
this.formats = void 0;
|
|
226
226
|
this.formatTokenMap = formatTokenMap;
|
|
@@ -285,10 +285,12 @@ export class AdapterDateFnsBase {
|
|
|
285
285
|
const {
|
|
286
286
|
locale,
|
|
287
287
|
formats,
|
|
288
|
-
longFormatters
|
|
288
|
+
longFormatters,
|
|
289
|
+
lib
|
|
289
290
|
} = props;
|
|
290
291
|
this.locale = locale;
|
|
291
292
|
this.formats = _extends({}, defaultFormats, formats);
|
|
292
293
|
this.longFormatters = longFormatters;
|
|
294
|
+
this.lib = lib || 'date-fns';
|
|
293
295
|
}
|
|
294
296
|
}
|
|
@@ -45,171 +45,7 @@ import isWithinInterval from 'date-fns-jalali/isWithinInterval';
|
|
|
45
45
|
import defaultLocale from 'date-fns-jalali/locale/fa-IR';
|
|
46
46
|
// @ts-ignore
|
|
47
47
|
import longFormatters from 'date-fns-jalali/_lib/format/longFormatters';
|
|
48
|
-
|
|
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
|
-
};
|
|
48
|
+
import { AdapterDateFnsBase } from '../AdapterDateFnsBase';
|
|
213
49
|
const defaultFormats = {
|
|
214
50
|
year: 'yyyy',
|
|
215
51
|
month: 'LLLL',
|
|
@@ -272,40 +108,22 @@ const NUMBER_SYMBOL_MAP = {
|
|
|
272
108
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
273
109
|
* SOFTWARE.
|
|
274
110
|
*/
|
|
275
|
-
export class AdapterDateFnsJalali {
|
|
111
|
+
export class AdapterDateFnsJalali extends AdapterDateFnsBase {
|
|
276
112
|
constructor({
|
|
277
|
-
locale
|
|
113
|
+
locale,
|
|
278
114
|
formats
|
|
279
115
|
} = {}) {
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
if (typeof value === 'undefined') {
|
|
292
|
-
return new Date();
|
|
293
|
-
}
|
|
294
|
-
if (value === null) {
|
|
295
|
-
return null;
|
|
296
|
-
}
|
|
297
|
-
return new Date(value);
|
|
298
|
-
};
|
|
299
|
-
this.getInvalidDate = () => new Date('Invalid Date');
|
|
300
|
-
this.getTimezone = () => {
|
|
301
|
-
return 'default';
|
|
302
|
-
};
|
|
303
|
-
this.setTimezone = value => {
|
|
304
|
-
return value;
|
|
305
|
-
};
|
|
306
|
-
this.toJsDate = value => {
|
|
307
|
-
return value;
|
|
308
|
-
};
|
|
116
|
+
if (typeof addDays !== 'function') {
|
|
117
|
+
throw new Error(['MUI: The `date-fns-jalali` package v3.x is not compatible with this adapter.', 'Please, install v2.x of the package or use the `AdapterDateFnsJalaliV3` instead.'].join('\n'));
|
|
118
|
+
}
|
|
119
|
+
super({
|
|
120
|
+
locale: locale ?? defaultLocale,
|
|
121
|
+
// some formats are different in jalali adapter,
|
|
122
|
+
// this ensures that `AdapterDateFnsBase` formats are overridden
|
|
123
|
+
formats: _extends({}, defaultFormats, formats),
|
|
124
|
+
longFormatters,
|
|
125
|
+
lib: 'date-fns-jalali'
|
|
126
|
+
});
|
|
309
127
|
this.parse = (value, format) => {
|
|
310
128
|
if (value === '') {
|
|
311
129
|
return null;
|
|
@@ -317,29 +135,6 @@ export class AdapterDateFnsJalali {
|
|
|
317
135
|
this.getCurrentLocaleCode = () => {
|
|
318
136
|
return this.locale?.code || 'fa-IR';
|
|
319
137
|
};
|
|
320
|
-
// Note: date-fns input types are more lenient than this adapter, so we need to expose our more
|
|
321
|
-
// strict signature and delegate to the more lenient signature. Otherwise, we have downstream type errors upon usage.
|
|
322
|
-
this.is12HourCycleInCurrentLocale = () => {
|
|
323
|
-
if (this.locale) {
|
|
324
|
-
return /a/.test(this.locale.formatLong.time());
|
|
325
|
-
}
|
|
326
|
-
|
|
327
|
-
// By default, date-fns-jalali is using fa-IR locale with am/pm enabled
|
|
328
|
-
return true;
|
|
329
|
-
};
|
|
330
|
-
this.expandFormat = format => {
|
|
331
|
-
// @see https://github.com/date-fns/date-fns/blob/master/src/format/index.js#L31
|
|
332
|
-
const longFormatRegexp = /P+p+|P+|p+|''|'(''|[^'])+('|$)|./g;
|
|
333
|
-
const locale = this.locale ?? defaultLocale;
|
|
334
|
-
return format.match(longFormatRegexp).map(token => {
|
|
335
|
-
const firstCharacter = token[0];
|
|
336
|
-
if (firstCharacter === 'p' || firstCharacter === 'P') {
|
|
337
|
-
const longFormatter = longFormatters[firstCharacter];
|
|
338
|
-
return longFormatter(token, locale.formatLong, {});
|
|
339
|
-
}
|
|
340
|
-
return token;
|
|
341
|
-
}).join('');
|
|
342
|
-
};
|
|
343
138
|
this.isValid = value => {
|
|
344
139
|
if (value == null) {
|
|
345
140
|
return false;
|
|
@@ -527,10 +322,5 @@ export class AdapterDateFnsJalali {
|
|
|
527
322
|
}
|
|
528
323
|
return years;
|
|
529
324
|
};
|
|
530
|
-
this.locale = _locale;
|
|
531
|
-
this.formats = _extends({}, defaultFormats, formats);
|
|
532
|
-
}
|
|
533
|
-
getDayOfWeek(value) {
|
|
534
|
-
return value.getDay() + 1;
|
|
535
325
|
}
|
|
536
326
|
}
|
|
@@ -0,0 +1,332 @@
|
|
|
1
|
+
import _extends from "@babel/runtime/helpers/esm/extends";
|
|
2
|
+
/* eslint-disable class-methods-use-this */
|
|
3
|
+
// TODO remove when date-fns-jalali-v3 is the default
|
|
4
|
+
// @ts-nocheck
|
|
5
|
+
import { addSeconds } from 'date-fns-jalali/addSeconds';
|
|
6
|
+
import { addMinutes } from 'date-fns-jalali/addMinutes';
|
|
7
|
+
import { addHours } from 'date-fns-jalali/addHours';
|
|
8
|
+
import { addDays } from 'date-fns-jalali/addDays';
|
|
9
|
+
import { addWeeks } from 'date-fns-jalali/addWeeks';
|
|
10
|
+
import { addMonths } from 'date-fns-jalali/addMonths';
|
|
11
|
+
import { addYears } from 'date-fns-jalali/addYears';
|
|
12
|
+
import { endOfDay } from 'date-fns-jalali/endOfDay';
|
|
13
|
+
import { endOfWeek } from 'date-fns-jalali/endOfWeek';
|
|
14
|
+
import { endOfYear } from 'date-fns-jalali/endOfYear';
|
|
15
|
+
import { format as dateFnsFormat, longFormatters } from 'date-fns-jalali/format';
|
|
16
|
+
import { getHours } from 'date-fns-jalali/getHours';
|
|
17
|
+
import { getSeconds } from 'date-fns-jalali/getSeconds';
|
|
18
|
+
import { getMilliseconds } from 'date-fns-jalali/getMilliseconds';
|
|
19
|
+
import { getWeek } from 'date-fns-jalali/getWeek';
|
|
20
|
+
import { getYear } from 'date-fns-jalali/getYear';
|
|
21
|
+
import { getMonth } from 'date-fns-jalali/getMonth';
|
|
22
|
+
import { getDate } from 'date-fns-jalali/getDate';
|
|
23
|
+
import { getDaysInMonth } from 'date-fns-jalali/getDaysInMonth';
|
|
24
|
+
import { getMinutes } from 'date-fns-jalali/getMinutes';
|
|
25
|
+
import { isAfter } from 'date-fns-jalali/isAfter';
|
|
26
|
+
import { isBefore } from 'date-fns-jalali/isBefore';
|
|
27
|
+
import { isEqual } from 'date-fns-jalali/isEqual';
|
|
28
|
+
import { isSameDay } from 'date-fns-jalali/isSameDay';
|
|
29
|
+
import { isSameYear } from 'date-fns-jalali/isSameYear';
|
|
30
|
+
import { isSameMonth } from 'date-fns-jalali/isSameMonth';
|
|
31
|
+
import { isSameHour } from 'date-fns-jalali/isSameHour';
|
|
32
|
+
import { isValid } from 'date-fns-jalali/isValid';
|
|
33
|
+
import { parse as dateFnsParse } from 'date-fns-jalali/parse';
|
|
34
|
+
import { setDate } from 'date-fns-jalali/setDate';
|
|
35
|
+
import { setHours } from 'date-fns-jalali/setHours';
|
|
36
|
+
import { setMinutes } from 'date-fns-jalali/setMinutes';
|
|
37
|
+
import { setMonth } from 'date-fns-jalali/setMonth';
|
|
38
|
+
import { setSeconds } from 'date-fns-jalali/setSeconds';
|
|
39
|
+
import { setMilliseconds } from 'date-fns-jalali/setMilliseconds';
|
|
40
|
+
import { setYear } from 'date-fns-jalali/setYear';
|
|
41
|
+
import { startOfDay } from 'date-fns-jalali/startOfDay';
|
|
42
|
+
import { startOfMonth } from 'date-fns-jalali/startOfMonth';
|
|
43
|
+
import { endOfMonth } from 'date-fns-jalali/endOfMonth';
|
|
44
|
+
import { startOfWeek } from 'date-fns-jalali/startOfWeek';
|
|
45
|
+
import { startOfYear } from 'date-fns-jalali/startOfYear';
|
|
46
|
+
import { isWithinInterval } from 'date-fns-jalali/isWithinInterval';
|
|
47
|
+
import { faIR as defaultLocale } from 'date-fns-jalali/locale/fa-IR';
|
|
48
|
+
// date-fns-jalali v2 does not export types
|
|
49
|
+
// @ts-ignore TODO remove when date-fns-jalali-v3 is the default
|
|
50
|
+
|
|
51
|
+
import { AdapterDateFnsBase } from '../AdapterDateFnsBase';
|
|
52
|
+
const defaultFormats = {
|
|
53
|
+
year: 'yyyy',
|
|
54
|
+
month: 'LLLL',
|
|
55
|
+
monthShort: 'MMM',
|
|
56
|
+
dayOfMonth: 'd',
|
|
57
|
+
dayOfMonthFull: 'do',
|
|
58
|
+
weekday: 'EEEE',
|
|
59
|
+
weekdayShort: 'EEEEEE',
|
|
60
|
+
hours24h: 'HH',
|
|
61
|
+
hours12h: 'hh',
|
|
62
|
+
meridiem: 'aa',
|
|
63
|
+
minutes: 'mm',
|
|
64
|
+
seconds: 'ss',
|
|
65
|
+
fullDate: 'PPP',
|
|
66
|
+
keyboardDate: 'P',
|
|
67
|
+
shortDate: 'd MMM',
|
|
68
|
+
normalDate: 'd MMMM',
|
|
69
|
+
normalDateWithWeekday: 'EEE, d MMMM',
|
|
70
|
+
fullTime: 'p',
|
|
71
|
+
fullTime12h: 'hh:mm aaa',
|
|
72
|
+
fullTime24h: 'HH:mm',
|
|
73
|
+
keyboardDateTime: 'P p',
|
|
74
|
+
keyboardDateTime12h: 'P hh:mm aa',
|
|
75
|
+
keyboardDateTime24h: 'P HH:mm'
|
|
76
|
+
};
|
|
77
|
+
const NUMBER_SYMBOL_MAP = {
|
|
78
|
+
'1': '۱',
|
|
79
|
+
'2': '۲',
|
|
80
|
+
'3': '۳',
|
|
81
|
+
'4': '۴',
|
|
82
|
+
'5': '۵',
|
|
83
|
+
'6': '۶',
|
|
84
|
+
'7': '۷',
|
|
85
|
+
'8': '۸',
|
|
86
|
+
'9': '۹',
|
|
87
|
+
'0': '۰'
|
|
88
|
+
};
|
|
89
|
+
/**
|
|
90
|
+
* Based on `@date-io/date-fns-jalali`
|
|
91
|
+
*
|
|
92
|
+
* MIT License
|
|
93
|
+
*
|
|
94
|
+
* Copyright (c) 2017 Dmitriy Kovalenko
|
|
95
|
+
*
|
|
96
|
+
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
97
|
+
* of this software and associated documentation files (the "Software"), to deal
|
|
98
|
+
* in the Software without restriction, including without limitation the rights
|
|
99
|
+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
100
|
+
* copies of the Software, and to permit persons to whom the Software is
|
|
101
|
+
* furnished to do so, subject to the following conditions:
|
|
102
|
+
*
|
|
103
|
+
* The above copyright notice and this permission notice shall be included in all
|
|
104
|
+
* copies or substantial portions of the Software.
|
|
105
|
+
*
|
|
106
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
107
|
+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
108
|
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
109
|
+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
110
|
+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
111
|
+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
112
|
+
* SOFTWARE.
|
|
113
|
+
*/
|
|
114
|
+
export class AdapterDateFnsJalali extends AdapterDateFnsBase {
|
|
115
|
+
constructor({
|
|
116
|
+
locale,
|
|
117
|
+
formats
|
|
118
|
+
} = {}) {
|
|
119
|
+
if (typeof addDays !== 'function') {
|
|
120
|
+
throw new Error([`MUI: The \`date-fns-jalali\` package v2.x is not compatible with this adapter.`, 'Please, install v3.x of the package or use the `AdapterDateFnsJalali` instead.'].join('\n'));
|
|
121
|
+
}
|
|
122
|
+
if (!longFormatters) {
|
|
123
|
+
throw new Error('MUI: The minimum supported `date-fns-jalali` package version compatible with this adapter is `3.2.x`.');
|
|
124
|
+
}
|
|
125
|
+
super({
|
|
126
|
+
locale: locale ?? defaultLocale,
|
|
127
|
+
// some formats are different in jalali adapter,
|
|
128
|
+
// this ensures that `AdapterDateFnsBase` formats are overridden
|
|
129
|
+
formats: _extends({}, defaultFormats, formats),
|
|
130
|
+
longFormatters,
|
|
131
|
+
lib: 'date-fns-jalali'
|
|
132
|
+
});
|
|
133
|
+
this.parse = (value, format) => {
|
|
134
|
+
if (value === '') {
|
|
135
|
+
return null;
|
|
136
|
+
}
|
|
137
|
+
return dateFnsParse(value, format, new Date(), {
|
|
138
|
+
locale: this.locale
|
|
139
|
+
});
|
|
140
|
+
};
|
|
141
|
+
this.getCurrentLocaleCode = () => {
|
|
142
|
+
return this.locale?.code || 'fa-IR';
|
|
143
|
+
};
|
|
144
|
+
this.isValid = value => {
|
|
145
|
+
if (value == null) {
|
|
146
|
+
return false;
|
|
147
|
+
}
|
|
148
|
+
return isValid(value);
|
|
149
|
+
};
|
|
150
|
+
this.format = (value, formatKey) => {
|
|
151
|
+
return this.formatByString(value, this.formats[formatKey]);
|
|
152
|
+
};
|
|
153
|
+
this.formatByString = (value, formatString) => {
|
|
154
|
+
return dateFnsFormat(value, formatString, {
|
|
155
|
+
locale: this.locale
|
|
156
|
+
});
|
|
157
|
+
};
|
|
158
|
+
this.formatNumber = numberToFormat => {
|
|
159
|
+
return numberToFormat.replace(/\d/g, match => NUMBER_SYMBOL_MAP[match]).replace(/,/g, '،');
|
|
160
|
+
};
|
|
161
|
+
this.isEqual = (value, comparing) => {
|
|
162
|
+
if (value === null && comparing === null) {
|
|
163
|
+
return true;
|
|
164
|
+
}
|
|
165
|
+
if (value === null || comparing === null) {
|
|
166
|
+
return false;
|
|
167
|
+
}
|
|
168
|
+
return isEqual(value, comparing);
|
|
169
|
+
};
|
|
170
|
+
this.isSameYear = (value, comparing) => {
|
|
171
|
+
return isSameYear(value, comparing);
|
|
172
|
+
};
|
|
173
|
+
this.isSameMonth = (value, comparing) => {
|
|
174
|
+
return isSameMonth(value, comparing);
|
|
175
|
+
};
|
|
176
|
+
this.isSameDay = (value, comparing) => {
|
|
177
|
+
return isSameDay(value, comparing);
|
|
178
|
+
};
|
|
179
|
+
this.isSameHour = (value, comparing) => {
|
|
180
|
+
return isSameHour(value, comparing);
|
|
181
|
+
};
|
|
182
|
+
this.isAfter = (value, comparing) => {
|
|
183
|
+
return isAfter(value, comparing);
|
|
184
|
+
};
|
|
185
|
+
this.isAfterYear = (value, comparing) => {
|
|
186
|
+
return isAfter(value, this.endOfYear(comparing));
|
|
187
|
+
};
|
|
188
|
+
this.isAfterDay = (value, comparing) => {
|
|
189
|
+
return isAfter(value, this.endOfDay(comparing));
|
|
190
|
+
};
|
|
191
|
+
this.isBefore = (value, comparing) => {
|
|
192
|
+
return isBefore(value, comparing);
|
|
193
|
+
};
|
|
194
|
+
this.isBeforeYear = (value, comparing) => {
|
|
195
|
+
return isBefore(value, this.startOfYear(comparing));
|
|
196
|
+
};
|
|
197
|
+
this.isBeforeDay = (value, comparing) => {
|
|
198
|
+
return isBefore(value, this.startOfDay(comparing));
|
|
199
|
+
};
|
|
200
|
+
this.isWithinRange = (value, [start, end]) => {
|
|
201
|
+
return isWithinInterval(value, {
|
|
202
|
+
start,
|
|
203
|
+
end
|
|
204
|
+
});
|
|
205
|
+
};
|
|
206
|
+
this.startOfYear = value => {
|
|
207
|
+
return startOfYear(value);
|
|
208
|
+
};
|
|
209
|
+
this.startOfMonth = value => {
|
|
210
|
+
return startOfMonth(value);
|
|
211
|
+
};
|
|
212
|
+
this.startOfWeek = value => {
|
|
213
|
+
return startOfWeek(value, {
|
|
214
|
+
locale: this.locale
|
|
215
|
+
});
|
|
216
|
+
};
|
|
217
|
+
this.startOfDay = value => {
|
|
218
|
+
return startOfDay(value);
|
|
219
|
+
};
|
|
220
|
+
this.endOfYear = value => {
|
|
221
|
+
return endOfYear(value);
|
|
222
|
+
};
|
|
223
|
+
this.endOfMonth = value => {
|
|
224
|
+
return endOfMonth(value);
|
|
225
|
+
};
|
|
226
|
+
this.endOfWeek = value => {
|
|
227
|
+
return endOfWeek(value, {
|
|
228
|
+
locale: this.locale
|
|
229
|
+
});
|
|
230
|
+
};
|
|
231
|
+
this.endOfDay = value => {
|
|
232
|
+
return endOfDay(value);
|
|
233
|
+
};
|
|
234
|
+
this.addYears = (value, amount) => {
|
|
235
|
+
return addYears(value, amount);
|
|
236
|
+
};
|
|
237
|
+
this.addMonths = (value, amount) => {
|
|
238
|
+
return addMonths(value, amount);
|
|
239
|
+
};
|
|
240
|
+
this.addWeeks = (value, amount) => {
|
|
241
|
+
return addWeeks(value, amount);
|
|
242
|
+
};
|
|
243
|
+
this.addDays = (value, amount) => {
|
|
244
|
+
return addDays(value, amount);
|
|
245
|
+
};
|
|
246
|
+
this.addHours = (value, amount) => {
|
|
247
|
+
return addHours(value, amount);
|
|
248
|
+
};
|
|
249
|
+
this.addMinutes = (value, amount) => {
|
|
250
|
+
return addMinutes(value, amount);
|
|
251
|
+
};
|
|
252
|
+
this.addSeconds = (value, amount) => {
|
|
253
|
+
return addSeconds(value, amount);
|
|
254
|
+
};
|
|
255
|
+
this.getYear = value => {
|
|
256
|
+
return getYear(value);
|
|
257
|
+
};
|
|
258
|
+
this.getMonth = value => {
|
|
259
|
+
return getMonth(value);
|
|
260
|
+
};
|
|
261
|
+
this.getDate = value => {
|
|
262
|
+
return getDate(value);
|
|
263
|
+
};
|
|
264
|
+
this.getHours = value => {
|
|
265
|
+
return getHours(value);
|
|
266
|
+
};
|
|
267
|
+
this.getMinutes = value => {
|
|
268
|
+
return getMinutes(value);
|
|
269
|
+
};
|
|
270
|
+
this.getSeconds = value => {
|
|
271
|
+
return getSeconds(value);
|
|
272
|
+
};
|
|
273
|
+
this.getMilliseconds = value => {
|
|
274
|
+
return getMilliseconds(value);
|
|
275
|
+
};
|
|
276
|
+
this.setYear = (value, year) => {
|
|
277
|
+
return setYear(value, year);
|
|
278
|
+
};
|
|
279
|
+
this.setMonth = (value, month) => {
|
|
280
|
+
return setMonth(value, month);
|
|
281
|
+
};
|
|
282
|
+
this.setDate = (value, date) => {
|
|
283
|
+
return setDate(value, date);
|
|
284
|
+
};
|
|
285
|
+
this.setHours = (value, hours) => {
|
|
286
|
+
return setHours(value, hours);
|
|
287
|
+
};
|
|
288
|
+
this.setMinutes = (value, minutes) => {
|
|
289
|
+
return setMinutes(value, minutes);
|
|
290
|
+
};
|
|
291
|
+
this.setSeconds = (value, seconds) => {
|
|
292
|
+
return setSeconds(value, seconds);
|
|
293
|
+
};
|
|
294
|
+
this.setMilliseconds = (value, milliseconds) => {
|
|
295
|
+
return setMilliseconds(value, milliseconds);
|
|
296
|
+
};
|
|
297
|
+
this.getDaysInMonth = value => {
|
|
298
|
+
return getDaysInMonth(value);
|
|
299
|
+
};
|
|
300
|
+
this.getWeekArray = value => {
|
|
301
|
+
const start = this.startOfWeek(this.startOfMonth(value));
|
|
302
|
+
const end = this.endOfWeek(this.endOfMonth(value));
|
|
303
|
+
let count = 0;
|
|
304
|
+
let current = start;
|
|
305
|
+
const nestedWeeks = [];
|
|
306
|
+
while (this.isBefore(current, end)) {
|
|
307
|
+
const weekNumber = Math.floor(count / 7);
|
|
308
|
+
nestedWeeks[weekNumber] = nestedWeeks[weekNumber] || [];
|
|
309
|
+
nestedWeeks[weekNumber].push(current);
|
|
310
|
+
current = this.addDays(current, 1);
|
|
311
|
+
count += 1;
|
|
312
|
+
}
|
|
313
|
+
return nestedWeeks;
|
|
314
|
+
};
|
|
315
|
+
this.getWeekNumber = date => {
|
|
316
|
+
return getWeek(date, {
|
|
317
|
+
locale: this.locale
|
|
318
|
+
});
|
|
319
|
+
};
|
|
320
|
+
this.getYearRange = ([start, end]) => {
|
|
321
|
+
const startDate = this.startOfYear(start);
|
|
322
|
+
const endDate = this.endOfYear(end);
|
|
323
|
+
const years = [];
|
|
324
|
+
let current = startDate;
|
|
325
|
+
while (this.isBefore(current, endDate)) {
|
|
326
|
+
years.push(current);
|
|
327
|
+
current = this.addYears(current, 1);
|
|
328
|
+
}
|
|
329
|
+
return years;
|
|
330
|
+
};
|
|
331
|
+
}
|
|
332
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { AdapterDateFnsJalali } from './AdapterDateFnsJalaliV3';
|