@mui/x-date-pickers 7.4.0 → 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 -227
- package/AdapterDateFnsJalaliV3/AdapterDateFnsJalaliV3.d.ts +3 -20
- package/AdapterDateFnsJalaliV3/AdapterDateFnsJalaliV3.js +17 -230
- package/AdapterDateFnsV3/AdapterDateFnsV3.d.ts +5 -0
- package/AdapterDateFnsV3/AdapterDateFnsV3.js +0 -1
- package/AdapterMomentJalaali/AdapterMomentJalaali.js +2 -6
- package/CHANGELOG.md +93 -0
- package/DateCalendar/DateCalendar.js +5 -4
- package/PickersLayout/usePickerLayout.js +6 -7
- package/index.js +1 -1
- package/internals/components/PickersModalDialog.d.ts +2 -2
- package/internals/demo/DemoContainer.js +1 -1
- package/internals/hooks/useField/useFieldV6TextField.js +1 -1
- package/internals/hooks/usePicker/usePickerViews.js +1 -0
- package/modern/AdapterDateFnsBase/AdapterDateFnsBase.js +4 -2
- package/modern/AdapterDateFnsJalali/AdapterDateFnsJalali.js +14 -227
- package/modern/AdapterDateFnsJalaliV3/AdapterDateFnsJalaliV3.js +17 -230
- 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/index.js +1 -1
- package/modern/internals/demo/DemoContainer.js +1 -1
- package/modern/internals/hooks/useField/useFieldV6TextField.js +1 -1
- package/modern/internals/hooks/usePicker/usePickerViews.js +1 -0
- package/node/AdapterDateFnsBase/AdapterDateFnsBase.js +4 -2
- package/node/AdapterDateFnsJalali/AdapterDateFnsJalali.js +14 -227
- package/node/AdapterDateFnsJalaliV3/AdapterDateFnsJalaliV3.js +17 -230
- package/node/AdapterMomentJalaali/AdapterMomentJalaali.js +2 -6
- package/node/DateCalendar/DateCalendar.js +5 -4
- package/node/PickersLayout/usePickerLayout.js +6 -7
- package/node/index.js +1 -1
- package/node/internals/demo/DemoContainer.js +1 -1
- package/node/internals/hooks/useField/useFieldV6TextField.js +1 -1
- package/node/internals/hooks/usePicker/usePickerViews.js +1 -0
- package/package.json +2 -2
|
@@ -3,6 +3,11 @@ import defaultLocale from 'date-fns/locale/en-US';
|
|
|
3
3
|
import { AdapterFormats, AdapterOptions, MuiPickersAdapter } from '../models';
|
|
4
4
|
import { AdapterDateFnsBase } from '../AdapterDateFnsBase';
|
|
5
5
|
type DateFnsLocale = typeof defaultLocale;
|
|
6
|
+
declare module '@mui/x-date-pickers/models' {
|
|
7
|
+
interface PickerValidDateLookup {
|
|
8
|
+
'date-fns': Date;
|
|
9
|
+
}
|
|
10
|
+
}
|
|
6
11
|
/**
|
|
7
12
|
* Based on `@date-io/date-fns`
|
|
8
13
|
*
|
|
@@ -10,12 +10,8 @@ type DateFnsLocaleBase = {
|
|
|
10
10
|
};
|
|
11
11
|
type DateFnsAdapterBaseOptions<DateFnsLocale extends DateFnsLocaleBase> = MakeRequired<AdapterOptions<DateFnsLocale, never>, 'locale'> & {
|
|
12
12
|
longFormatters: Record<'p' | 'P', (token: string, formatLong: any) => string>;
|
|
13
|
+
lib?: string;
|
|
13
14
|
};
|
|
14
|
-
declare module '@mui/x-date-pickers/models' {
|
|
15
|
-
interface PickerValidDateLookup {
|
|
16
|
-
'date-fns': Date;
|
|
17
|
-
}
|
|
18
|
-
}
|
|
19
15
|
/**
|
|
20
16
|
* Based on `@date-io/date-fns`
|
|
21
17
|
*
|
|
@@ -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
|
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
/// <reference types="date-fns-jalali" />
|
|
2
2
|
import defaultLocale from 'date-fns-jalali/locale/fa-IR';
|
|
3
|
-
import { AdapterFormats, AdapterOptions,
|
|
3
|
+
import { AdapterFormats, AdapterOptions, MuiPickersAdapter } from '../models';
|
|
4
|
+
import { AdapterDateFnsBase } from '../AdapterDateFnsBase';
|
|
4
5
|
type DateFnsLocale = typeof defaultLocale;
|
|
5
6
|
declare module '@mui/x-date-pickers/models' {
|
|
6
7
|
interface PickerValidDateLookup {
|
|
@@ -32,27 +33,10 @@ declare module '@mui/x-date-pickers/models' {
|
|
|
32
33
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
33
34
|
* SOFTWARE.
|
|
34
35
|
*/
|
|
35
|
-
export declare class AdapterDateFnsJalali implements MuiPickersAdapter<Date, DateFnsLocale> {
|
|
36
|
-
isMUIAdapter: boolean;
|
|
37
|
-
isTimezoneCompatible: boolean;
|
|
38
|
-
lib: string;
|
|
39
|
-
locale?: DateFnsLocale;
|
|
40
|
-
formats: AdapterFormats;
|
|
41
|
-
formatTokenMap: FieldFormatTokenMap;
|
|
42
|
-
escapedCharacters: {
|
|
43
|
-
start: string;
|
|
44
|
-
end: string;
|
|
45
|
-
};
|
|
36
|
+
export declare class AdapterDateFnsJalali extends AdapterDateFnsBase<DateFnsLocale> implements MuiPickersAdapter<Date, DateFnsLocale> {
|
|
46
37
|
constructor({ locale, formats }?: AdapterOptions<DateFnsLocale, never>);
|
|
47
|
-
date: <T extends string | null | undefined>(value?: T) => DateBuilderReturnType<T, Date>;
|
|
48
|
-
getInvalidDate: () => Date;
|
|
49
|
-
getTimezone: () => string;
|
|
50
|
-
setTimezone: (value: Date) => Date;
|
|
51
|
-
toJsDate: (value: Date) => Date;
|
|
52
38
|
parse: (value: string, format: string) => Date | null;
|
|
53
39
|
getCurrentLocaleCode: () => string;
|
|
54
|
-
is12HourCycleInCurrentLocale: () => boolean;
|
|
55
|
-
expandFormat: (format: string) => string;
|
|
56
40
|
isValid: (value: Date | null) => boolean;
|
|
57
41
|
format: (value: Date, formatKey: keyof AdapterFormats) => string;
|
|
58
42
|
formatByString: (value: Date, formatString: string) => string;
|
|
@@ -101,7 +85,6 @@ export declare class AdapterDateFnsJalali implements MuiPickersAdapter<Date, Dat
|
|
|
101
85
|
getDaysInMonth: (value: Date) => number;
|
|
102
86
|
getWeekArray: (value: Date) => Date[][];
|
|
103
87
|
getWeekNumber: (date: Date) => number;
|
|
104
|
-
getDayOfWeek(value: Date): number;
|
|
105
88
|
getYearRange: ([start, end]: [Date, Date]) => Date[];
|
|
106
89
|
}
|
|
107
90
|
export {};
|
|
@@ -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,13 +322,5 @@ export class AdapterDateFnsJalali {
|
|
|
527
322
|
}
|
|
528
323
|
return years;
|
|
529
324
|
};
|
|
530
|
-
if (typeof addDays !== 'function') {
|
|
531
|
-
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'));
|
|
532
|
-
}
|
|
533
|
-
this.locale = _locale;
|
|
534
|
-
this.formats = _extends({}, defaultFormats, formats);
|
|
535
|
-
}
|
|
536
|
-
getDayOfWeek(value) {
|
|
537
|
-
return value.getDay() + 1;
|
|
538
325
|
}
|
|
539
326
|
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { Locale as DateFnsLocale } from 'date-fns-jalali/locale/types';
|
|
2
|
-
import { AdapterFormats, AdapterOptions,
|
|
2
|
+
import { AdapterFormats, AdapterOptions, MuiPickersAdapter } from '../models';
|
|
3
|
+
import { AdapterDateFnsBase } from '../AdapterDateFnsBase';
|
|
3
4
|
declare module '@mui/x-date-pickers/models' {
|
|
4
5
|
interface PickerValidDateLookup {
|
|
5
6
|
'date-fns-jalali': Date;
|
|
@@ -30,27 +31,10 @@ declare module '@mui/x-date-pickers/models' {
|
|
|
30
31
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
31
32
|
* SOFTWARE.
|
|
32
33
|
*/
|
|
33
|
-
export declare class AdapterDateFnsJalali implements MuiPickersAdapter<Date, DateFnsLocale> {
|
|
34
|
-
isMUIAdapter: boolean;
|
|
35
|
-
isTimezoneCompatible: boolean;
|
|
36
|
-
lib: string;
|
|
37
|
-
locale?: DateFnsLocale;
|
|
38
|
-
formats: AdapterFormats;
|
|
39
|
-
formatTokenMap: FieldFormatTokenMap;
|
|
40
|
-
escapedCharacters: {
|
|
41
|
-
start: string;
|
|
42
|
-
end: string;
|
|
43
|
-
};
|
|
34
|
+
export declare class AdapterDateFnsJalali extends AdapterDateFnsBase<DateFnsLocale> implements MuiPickersAdapter<Date, DateFnsLocale> {
|
|
44
35
|
constructor({ locale, formats }?: AdapterOptions<DateFnsLocale, never>);
|
|
45
|
-
date: <T extends string | null | undefined>(value?: T) => DateBuilderReturnType<T, Date>;
|
|
46
|
-
getInvalidDate: () => Date;
|
|
47
|
-
getTimezone: () => string;
|
|
48
|
-
setTimezone: (value: Date) => Date;
|
|
49
|
-
toJsDate: (value: Date) => Date;
|
|
50
36
|
parse: (value: string, format: string) => any;
|
|
51
37
|
getCurrentLocaleCode: () => any;
|
|
52
|
-
is12HourCycleInCurrentLocale: () => boolean;
|
|
53
|
-
expandFormat: (format: string) => string;
|
|
54
38
|
isValid: (value: Date | null) => any;
|
|
55
39
|
format: (value: Date, formatKey: keyof AdapterFormats) => any;
|
|
56
40
|
formatByString: (value: Date, formatString: string) => any;
|
|
@@ -99,6 +83,5 @@ export declare class AdapterDateFnsJalali implements MuiPickersAdapter<Date, Dat
|
|
|
99
83
|
getDaysInMonth: (value: Date) => any;
|
|
100
84
|
getWeekArray: (value: Date) => Date[][];
|
|
101
85
|
getWeekNumber: (date: Date) => any;
|
|
102
|
-
getDayOfWeek(value: Date): number;
|
|
103
86
|
getYearRange: ([start, end]: [Date, Date]) => Date[];
|
|
104
87
|
}
|
|
@@ -48,171 +48,7 @@ import { faIR as defaultLocale } from 'date-fns-jalali/locale/fa-IR';
|
|
|
48
48
|
// date-fns-jalali v2 does not export types
|
|
49
49
|
// @ts-ignore TODO remove when date-fns-jalali-v3 is the default
|
|
50
50
|
|
|
51
|
-
|
|
52
|
-
// Year
|
|
53
|
-
y: {
|
|
54
|
-
sectionType: 'year',
|
|
55
|
-
contentType: 'digit',
|
|
56
|
-
maxLength: 4
|
|
57
|
-
},
|
|
58
|
-
yy: 'year',
|
|
59
|
-
yyy: {
|
|
60
|
-
sectionType: 'year',
|
|
61
|
-
contentType: 'digit',
|
|
62
|
-
maxLength: 4
|
|
63
|
-
},
|
|
64
|
-
yyyy: 'year',
|
|
65
|
-
// Month
|
|
66
|
-
M: {
|
|
67
|
-
sectionType: 'month',
|
|
68
|
-
contentType: 'digit',
|
|
69
|
-
maxLength: 2
|
|
70
|
-
},
|
|
71
|
-
MM: 'month',
|
|
72
|
-
MMMM: {
|
|
73
|
-
sectionType: 'month',
|
|
74
|
-
contentType: 'letter'
|
|
75
|
-
},
|
|
76
|
-
MMM: {
|
|
77
|
-
sectionType: 'month',
|
|
78
|
-
contentType: 'letter'
|
|
79
|
-
},
|
|
80
|
-
L: {
|
|
81
|
-
sectionType: 'month',
|
|
82
|
-
contentType: 'digit',
|
|
83
|
-
maxLength: 2
|
|
84
|
-
},
|
|
85
|
-
LL: 'month',
|
|
86
|
-
LLL: {
|
|
87
|
-
sectionType: 'month',
|
|
88
|
-
contentType: 'letter'
|
|
89
|
-
},
|
|
90
|
-
LLLL: {
|
|
91
|
-
sectionType: 'month',
|
|
92
|
-
contentType: 'letter'
|
|
93
|
-
},
|
|
94
|
-
// Day of the month
|
|
95
|
-
d: {
|
|
96
|
-
sectionType: 'day',
|
|
97
|
-
contentType: 'digit',
|
|
98
|
-
maxLength: 2
|
|
99
|
-
},
|
|
100
|
-
dd: 'day',
|
|
101
|
-
do: {
|
|
102
|
-
sectionType: 'day',
|
|
103
|
-
contentType: 'digit-with-letter'
|
|
104
|
-
},
|
|
105
|
-
// Day of the week
|
|
106
|
-
E: {
|
|
107
|
-
sectionType: 'weekDay',
|
|
108
|
-
contentType: 'letter'
|
|
109
|
-
},
|
|
110
|
-
EE: {
|
|
111
|
-
sectionType: 'weekDay',
|
|
112
|
-
contentType: 'letter'
|
|
113
|
-
},
|
|
114
|
-
EEE: {
|
|
115
|
-
sectionType: 'weekDay',
|
|
116
|
-
contentType: 'letter'
|
|
117
|
-
},
|
|
118
|
-
EEEE: {
|
|
119
|
-
sectionType: 'weekDay',
|
|
120
|
-
contentType: 'letter'
|
|
121
|
-
},
|
|
122
|
-
EEEEE: {
|
|
123
|
-
sectionType: 'weekDay',
|
|
124
|
-
contentType: 'letter'
|
|
125
|
-
},
|
|
126
|
-
i: {
|
|
127
|
-
sectionType: 'weekDay',
|
|
128
|
-
contentType: 'digit',
|
|
129
|
-
maxLength: 1
|
|
130
|
-
},
|
|
131
|
-
ii: 'weekDay',
|
|
132
|
-
iii: {
|
|
133
|
-
sectionType: 'weekDay',
|
|
134
|
-
contentType: 'letter'
|
|
135
|
-
},
|
|
136
|
-
iiii: {
|
|
137
|
-
sectionType: 'weekDay',
|
|
138
|
-
contentType: 'letter'
|
|
139
|
-
},
|
|
140
|
-
e: {
|
|
141
|
-
sectionType: 'weekDay',
|
|
142
|
-
contentType: 'digit',
|
|
143
|
-
maxLength: 1
|
|
144
|
-
},
|
|
145
|
-
ee: 'weekDay',
|
|
146
|
-
eee: {
|
|
147
|
-
sectionType: 'weekDay',
|
|
148
|
-
contentType: 'letter'
|
|
149
|
-
},
|
|
150
|
-
eeee: {
|
|
151
|
-
sectionType: 'weekDay',
|
|
152
|
-
contentType: 'letter'
|
|
153
|
-
},
|
|
154
|
-
eeeee: {
|
|
155
|
-
sectionType: 'weekDay',
|
|
156
|
-
contentType: 'letter'
|
|
157
|
-
},
|
|
158
|
-
eeeeee: {
|
|
159
|
-
sectionType: 'weekDay',
|
|
160
|
-
contentType: 'letter'
|
|
161
|
-
},
|
|
162
|
-
c: {
|
|
163
|
-
sectionType: 'weekDay',
|
|
164
|
-
contentType: 'digit',
|
|
165
|
-
maxLength: 1
|
|
166
|
-
},
|
|
167
|
-
cc: 'weekDay',
|
|
168
|
-
ccc: {
|
|
169
|
-
sectionType: 'weekDay',
|
|
170
|
-
contentType: 'letter'
|
|
171
|
-
},
|
|
172
|
-
cccc: {
|
|
173
|
-
sectionType: 'weekDay',
|
|
174
|
-
contentType: 'letter'
|
|
175
|
-
},
|
|
176
|
-
ccccc: {
|
|
177
|
-
sectionType: 'weekDay',
|
|
178
|
-
contentType: 'letter'
|
|
179
|
-
},
|
|
180
|
-
cccccc: {
|
|
181
|
-
sectionType: 'weekDay',
|
|
182
|
-
contentType: 'letter'
|
|
183
|
-
},
|
|
184
|
-
// Meridiem
|
|
185
|
-
a: 'meridiem',
|
|
186
|
-
aa: 'meridiem',
|
|
187
|
-
aaa: 'meridiem',
|
|
188
|
-
// Hours
|
|
189
|
-
H: {
|
|
190
|
-
sectionType: 'hours',
|
|
191
|
-
contentType: 'digit',
|
|
192
|
-
maxLength: 2
|
|
193
|
-
},
|
|
194
|
-
HH: 'hours',
|
|
195
|
-
h: {
|
|
196
|
-
sectionType: 'hours',
|
|
197
|
-
contentType: 'digit',
|
|
198
|
-
maxLength: 2
|
|
199
|
-
},
|
|
200
|
-
hh: 'hours',
|
|
201
|
-
// Minutes
|
|
202
|
-
m: {
|
|
203
|
-
sectionType: 'minutes',
|
|
204
|
-
contentType: 'digit',
|
|
205
|
-
maxLength: 2
|
|
206
|
-
},
|
|
207
|
-
mm: 'minutes',
|
|
208
|
-
// Seconds
|
|
209
|
-
s: {
|
|
210
|
-
sectionType: 'seconds',
|
|
211
|
-
contentType: 'digit',
|
|
212
|
-
maxLength: 2
|
|
213
|
-
},
|
|
214
|
-
ss: 'seconds'
|
|
215
|
-
};
|
|
51
|
+
import { AdapterDateFnsBase } from '../AdapterDateFnsBase';
|
|
216
52
|
const defaultFormats = {
|
|
217
53
|
year: 'yyyy',
|
|
218
54
|
month: 'LLLL',
|
|
@@ -275,40 +111,25 @@ const NUMBER_SYMBOL_MAP = {
|
|
|
275
111
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
276
112
|
* SOFTWARE.
|
|
277
113
|
*/
|
|
278
|
-
export class AdapterDateFnsJalali {
|
|
114
|
+
export class AdapterDateFnsJalali extends AdapterDateFnsBase {
|
|
279
115
|
constructor({
|
|
280
|
-
locale
|
|
116
|
+
locale,
|
|
281
117
|
formats
|
|
282
118
|
} = {}) {
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
if (value === null) {
|
|
298
|
-
return null;
|
|
299
|
-
}
|
|
300
|
-
return new Date(value);
|
|
301
|
-
};
|
|
302
|
-
this.getInvalidDate = () => new Date('Invalid Date');
|
|
303
|
-
this.getTimezone = () => {
|
|
304
|
-
return 'default';
|
|
305
|
-
};
|
|
306
|
-
this.setTimezone = value => {
|
|
307
|
-
return value;
|
|
308
|
-
};
|
|
309
|
-
this.toJsDate = value => {
|
|
310
|
-
return value;
|
|
311
|
-
};
|
|
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
|
+
});
|
|
312
133
|
this.parse = (value, format) => {
|
|
313
134
|
if (value === '') {
|
|
314
135
|
return null;
|
|
@@ -320,29 +141,6 @@ export class AdapterDateFnsJalali {
|
|
|
320
141
|
this.getCurrentLocaleCode = () => {
|
|
321
142
|
return this.locale?.code || 'fa-IR';
|
|
322
143
|
};
|
|
323
|
-
// Note: date-fns input types are more lenient than this adapter, so we need to expose our more
|
|
324
|
-
// strict signature and delegate to the more lenient signature. Otherwise, we have downstream type errors upon usage.
|
|
325
|
-
this.is12HourCycleInCurrentLocale = () => {
|
|
326
|
-
if (this.locale) {
|
|
327
|
-
return /a/.test(this.locale.formatLong.time());
|
|
328
|
-
}
|
|
329
|
-
|
|
330
|
-
// By default, date-fns-jalali is using fa-IR locale with am/pm enabled
|
|
331
|
-
return true;
|
|
332
|
-
};
|
|
333
|
-
this.expandFormat = format => {
|
|
334
|
-
// @see https://github.com/date-fns/date-fns/blob/master/src/format/index.js#L31
|
|
335
|
-
const longFormatRegexp = /P+p+|P+|p+|''|'(''|[^'])+('|$)|./g;
|
|
336
|
-
const locale = this.locale ?? defaultLocale;
|
|
337
|
-
return format.match(longFormatRegexp).map(token => {
|
|
338
|
-
const firstCharacter = token[0];
|
|
339
|
-
if (firstCharacter === 'p' || firstCharacter === 'P') {
|
|
340
|
-
const longFormatter = longFormatters[firstCharacter];
|
|
341
|
-
return longFormatter(token, locale.formatLong, {});
|
|
342
|
-
}
|
|
343
|
-
return token;
|
|
344
|
-
}).join('');
|
|
345
|
-
};
|
|
346
144
|
this.isValid = value => {
|
|
347
145
|
if (value == null) {
|
|
348
146
|
return false;
|
|
@@ -530,16 +328,5 @@ export class AdapterDateFnsJalali {
|
|
|
530
328
|
}
|
|
531
329
|
return years;
|
|
532
330
|
};
|
|
533
|
-
if (typeof addDays !== 'function') {
|
|
534
|
-
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'));
|
|
535
|
-
}
|
|
536
|
-
if (!longFormatters) {
|
|
537
|
-
throw new Error('MUI: The minimum supported `date-fns-jalali` package version compatible with this adapter is `3.2.x`.');
|
|
538
|
-
}
|
|
539
|
-
this.locale = _locale;
|
|
540
|
-
this.formats = _extends({}, defaultFormats, formats);
|
|
541
|
-
}
|
|
542
|
-
getDayOfWeek(value) {
|
|
543
|
-
return value.getDay() + 1;
|
|
544
331
|
}
|
|
545
332
|
}
|
|
@@ -1,6 +1,11 @@
|
|
|
1
1
|
import { Locale as DateFnsLocale } from 'date-fns/locale/types';
|
|
2
2
|
import { AdapterFormats, AdapterOptions, MuiPickersAdapter } from '../models';
|
|
3
3
|
import { AdapterDateFnsBase } from '../AdapterDateFnsBase';
|
|
4
|
+
declare module '@mui/x-date-pickers/models' {
|
|
5
|
+
interface PickerValidDateLookup {
|
|
6
|
+
'date-fns': Date;
|
|
7
|
+
}
|
|
8
|
+
}
|
|
4
9
|
/**
|
|
5
10
|
* Based on `@date-io/date-fns`
|
|
6
11
|
*
|