@mui/x-date-pickers 8.10.0 → 8.10.2

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.
@@ -88,198 +88,199 @@ export class AdapterDateFns extends AdapterDateFnsBase {
88
88
  formats,
89
89
  longFormatters
90
90
  });
91
- // TODO: explicit return types can be removed once there is only one date-fns version supported
92
- this.parse = (value, format) => {
93
- if (value === '') {
94
- return null;
95
- }
96
- return dateFnsParse(value, format, new Date(), {
97
- locale: this.locale
98
- });
99
- };
100
- this.isValid = value => {
101
- if (value == null) {
102
- return false;
103
- }
104
- return isValid(value);
105
- };
106
- this.format = (value, formatKey) => {
107
- return this.formatByString(value, this.formats[formatKey]);
108
- };
109
- this.formatByString = (value, formatString) => {
110
- return dateFnsFormat(value, formatString, {
111
- locale: this.locale
112
- });
113
- };
114
- this.isEqual = (value, comparing) => {
115
- if (value === null && comparing === null) {
116
- return true;
117
- }
118
- if (value === null || comparing === null) {
119
- return false;
120
- }
121
- return isEqual(value, comparing);
122
- };
123
- this.isSameYear = (value, comparing) => {
124
- return isSameYear(value, comparing);
125
- };
126
- this.isSameMonth = (value, comparing) => {
127
- return isSameMonth(value, comparing);
128
- };
129
- this.isSameDay = (value, comparing) => {
130
- return isSameDay(value, comparing);
131
- };
132
- this.isSameHour = (value, comparing) => {
133
- return isSameHour(value, comparing);
134
- };
135
- this.isAfter = (value, comparing) => {
136
- return isAfter(value, comparing);
137
- };
138
- this.isAfterYear = (value, comparing) => {
139
- return isAfter(value, endOfYear(comparing));
140
- };
141
- this.isAfterDay = (value, comparing) => {
142
- return isAfter(value, endOfDay(comparing));
143
- };
144
- this.isBefore = (value, comparing) => {
145
- return isBefore(value, comparing);
146
- };
147
- this.isBeforeYear = (value, comparing) => {
148
- return isBefore(value, this.startOfYear(comparing));
149
- };
150
- this.isBeforeDay = (value, comparing) => {
151
- return isBefore(value, this.startOfDay(comparing));
152
- };
153
- this.isWithinRange = (value, [start, end]) => {
154
- return isWithinInterval(value, {
155
- start,
156
- end
157
- });
158
- };
159
- this.startOfYear = value => {
160
- return startOfYear(value);
161
- };
162
- this.startOfMonth = value => {
163
- return startOfMonth(value);
164
- };
165
- this.startOfWeek = value => {
166
- return startOfWeek(value, {
167
- locale: this.locale
168
- });
169
- };
170
- this.startOfDay = value => {
171
- return startOfDay(value);
172
- };
173
- this.endOfYear = value => {
174
- return endOfYear(value);
175
- };
176
- this.endOfMonth = value => {
177
- return endOfMonth(value);
178
- };
179
- this.endOfWeek = value => {
180
- return endOfWeek(value, {
181
- locale: this.locale
182
- });
183
- };
184
- this.endOfDay = value => {
185
- return endOfDay(value);
186
- };
187
- this.addYears = (value, amount) => {
188
- return addYears(value, amount);
189
- };
190
- this.addMonths = (value, amount) => {
191
- return addMonths(value, amount);
192
- };
193
- this.addWeeks = (value, amount) => {
194
- return addWeeks(value, amount);
195
- };
196
- this.addDays = (value, amount) => {
197
- return addDays(value, amount);
198
- };
199
- this.addHours = (value, amount) => {
200
- return addHours(value, amount);
201
- };
202
- this.addMinutes = (value, amount) => {
203
- return addMinutes(value, amount);
204
- };
205
- this.addSeconds = (value, amount) => {
206
- return addSeconds(value, amount);
207
- };
208
- this.getYear = value => {
209
- return getYear(value);
210
- };
211
- this.getMonth = value => {
212
- return getMonth(value);
213
- };
214
- this.getDate = value => {
215
- return getDate(value);
216
- };
217
- this.getHours = value => {
218
- return getHours(value);
219
- };
220
- this.getMinutes = value => {
221
- return getMinutes(value);
222
- };
223
- this.getSeconds = value => {
224
- return getSeconds(value);
225
- };
226
- this.getMilliseconds = value => {
227
- return getMilliseconds(value);
228
- };
229
- this.setYear = (value, year) => {
230
- return setYear(value, year);
231
- };
232
- this.setMonth = (value, month) => {
233
- return setMonth(value, month);
234
- };
235
- this.setDate = (value, date) => {
236
- return setDate(value, date);
237
- };
238
- this.setHours = (value, hours) => {
239
- return setHours(value, hours);
240
- };
241
- this.setMinutes = (value, minutes) => {
242
- return setMinutes(value, minutes);
243
- };
244
- this.setSeconds = (value, seconds) => {
245
- return setSeconds(value, seconds);
246
- };
247
- this.setMilliseconds = (value, milliseconds) => {
248
- return setMilliseconds(value, milliseconds);
249
- };
250
- this.getDaysInMonth = value => {
251
- return getDaysInMonth(value);
252
- };
253
- this.getWeekArray = value => {
254
- const start = this.startOfWeek(this.startOfMonth(value));
255
- const end = this.endOfWeek(this.endOfMonth(value));
256
- let count = 0;
257
- let current = start;
258
- const nestedWeeks = [];
259
- while (this.isBefore(current, end)) {
260
- const weekNumber = Math.floor(count / 7);
261
- nestedWeeks[weekNumber] = nestedWeeks[weekNumber] || [];
262
- nestedWeeks[weekNumber].push(current);
263
- current = this.addDays(current, 1);
264
- count += 1;
265
- }
266
- return nestedWeeks;
267
- };
268
- this.getWeekNumber = value => {
269
- return getWeek(value, {
270
- locale: this.locale
271
- });
272
- };
273
- this.getYearRange = ([start, end]) => {
274
- const startDate = this.startOfYear(start);
275
- const endDate = this.endOfYear(end);
276
- const years = [];
277
- let current = startDate;
278
- while (this.isBefore(current, endDate)) {
279
- years.push(current);
280
- current = this.addYears(current, 1);
281
- }
282
- return years;
283
- };
284
91
  }
92
+
93
+ // TODO: explicit return types can be removed once there is only one date-fns version supported
94
+ parse = (value, format) => {
95
+ if (value === '') {
96
+ return null;
97
+ }
98
+ return dateFnsParse(value, format, new Date(), {
99
+ locale: this.locale
100
+ });
101
+ };
102
+ isValid = value => {
103
+ if (value == null) {
104
+ return false;
105
+ }
106
+ return isValid(value);
107
+ };
108
+ format = (value, formatKey) => {
109
+ return this.formatByString(value, this.formats[formatKey]);
110
+ };
111
+ formatByString = (value, formatString) => {
112
+ return dateFnsFormat(value, formatString, {
113
+ locale: this.locale
114
+ });
115
+ };
116
+ isEqual = (value, comparing) => {
117
+ if (value === null && comparing === null) {
118
+ return true;
119
+ }
120
+ if (value === null || comparing === null) {
121
+ return false;
122
+ }
123
+ return isEqual(value, comparing);
124
+ };
125
+ isSameYear = (value, comparing) => {
126
+ return isSameYear(value, comparing);
127
+ };
128
+ isSameMonth = (value, comparing) => {
129
+ return isSameMonth(value, comparing);
130
+ };
131
+ isSameDay = (value, comparing) => {
132
+ return isSameDay(value, comparing);
133
+ };
134
+ isSameHour = (value, comparing) => {
135
+ return isSameHour(value, comparing);
136
+ };
137
+ isAfter = (value, comparing) => {
138
+ return isAfter(value, comparing);
139
+ };
140
+ isAfterYear = (value, comparing) => {
141
+ return isAfter(value, endOfYear(comparing));
142
+ };
143
+ isAfterDay = (value, comparing) => {
144
+ return isAfter(value, endOfDay(comparing));
145
+ };
146
+ isBefore = (value, comparing) => {
147
+ return isBefore(value, comparing);
148
+ };
149
+ isBeforeYear = (value, comparing) => {
150
+ return isBefore(value, this.startOfYear(comparing));
151
+ };
152
+ isBeforeDay = (value, comparing) => {
153
+ return isBefore(value, this.startOfDay(comparing));
154
+ };
155
+ isWithinRange = (value, [start, end]) => {
156
+ return isWithinInterval(value, {
157
+ start,
158
+ end
159
+ });
160
+ };
161
+ startOfYear = value => {
162
+ return startOfYear(value);
163
+ };
164
+ startOfMonth = value => {
165
+ return startOfMonth(value);
166
+ };
167
+ startOfWeek = value => {
168
+ return startOfWeek(value, {
169
+ locale: this.locale
170
+ });
171
+ };
172
+ startOfDay = value => {
173
+ return startOfDay(value);
174
+ };
175
+ endOfYear = value => {
176
+ return endOfYear(value);
177
+ };
178
+ endOfMonth = value => {
179
+ return endOfMonth(value);
180
+ };
181
+ endOfWeek = value => {
182
+ return endOfWeek(value, {
183
+ locale: this.locale
184
+ });
185
+ };
186
+ endOfDay = value => {
187
+ return endOfDay(value);
188
+ };
189
+ addYears = (value, amount) => {
190
+ return addYears(value, amount);
191
+ };
192
+ addMonths = (value, amount) => {
193
+ return addMonths(value, amount);
194
+ };
195
+ addWeeks = (value, amount) => {
196
+ return addWeeks(value, amount);
197
+ };
198
+ addDays = (value, amount) => {
199
+ return addDays(value, amount);
200
+ };
201
+ addHours = (value, amount) => {
202
+ return addHours(value, amount);
203
+ };
204
+ addMinutes = (value, amount) => {
205
+ return addMinutes(value, amount);
206
+ };
207
+ addSeconds = (value, amount) => {
208
+ return addSeconds(value, amount);
209
+ };
210
+ getYear = value => {
211
+ return getYear(value);
212
+ };
213
+ getMonth = value => {
214
+ return getMonth(value);
215
+ };
216
+ getDate = value => {
217
+ return getDate(value);
218
+ };
219
+ getHours = value => {
220
+ return getHours(value);
221
+ };
222
+ getMinutes = value => {
223
+ return getMinutes(value);
224
+ };
225
+ getSeconds = value => {
226
+ return getSeconds(value);
227
+ };
228
+ getMilliseconds = value => {
229
+ return getMilliseconds(value);
230
+ };
231
+ setYear = (value, year) => {
232
+ return setYear(value, year);
233
+ };
234
+ setMonth = (value, month) => {
235
+ return setMonth(value, month);
236
+ };
237
+ setDate = (value, date) => {
238
+ return setDate(value, date);
239
+ };
240
+ setHours = (value, hours) => {
241
+ return setHours(value, hours);
242
+ };
243
+ setMinutes = (value, minutes) => {
244
+ return setMinutes(value, minutes);
245
+ };
246
+ setSeconds = (value, seconds) => {
247
+ return setSeconds(value, seconds);
248
+ };
249
+ setMilliseconds = (value, milliseconds) => {
250
+ return setMilliseconds(value, milliseconds);
251
+ };
252
+ getDaysInMonth = value => {
253
+ return getDaysInMonth(value);
254
+ };
255
+ getWeekArray = value => {
256
+ const start = this.startOfWeek(this.startOfMonth(value));
257
+ const end = this.endOfWeek(this.endOfMonth(value));
258
+ let count = 0;
259
+ let current = start;
260
+ const nestedWeeks = [];
261
+ while (this.isBefore(current, end)) {
262
+ const weekNumber = Math.floor(count / 7);
263
+ nestedWeeks[weekNumber] = nestedWeeks[weekNumber] || [];
264
+ nestedWeeks[weekNumber].push(current);
265
+ current = this.addDays(current, 1);
266
+ count += 1;
267
+ }
268
+ return nestedWeeks;
269
+ };
270
+ getWeekNumber = value => {
271
+ return getWeek(value, {
272
+ locale: this.locale
273
+ });
274
+ };
275
+ getYearRange = ([start, end]) => {
276
+ const startDate = this.startOfYear(start);
277
+ const endDate = this.endOfYear(end);
278
+ const years = [];
279
+ let current = startDate;
280
+ while (this.isBefore(current, endDate)) {
281
+ years.push(current);
282
+ current = this.addYears(current, 1);
283
+ }
284
+ return years;
285
+ };
285
286
  }
@@ -216,67 +216,14 @@ const defaultFormats = {
216
216
  * SOFTWARE.
217
217
  */
218
218
  export class AdapterDateFnsBase {
219
+ isMUIAdapter = true;
220
+ isTimezoneCompatible = false;
221
+ formatTokenMap = (() => formatTokenMap)();
222
+ escapedCharacters = {
223
+ start: "'",
224
+ end: "'"
225
+ };
219
226
  constructor(props) {
220
- this.isMUIAdapter = true;
221
- this.isTimezoneCompatible = false;
222
- this.lib = void 0;
223
- this.locale = void 0;
224
- this.formats = void 0;
225
- this.formatTokenMap = formatTokenMap;
226
- this.escapedCharacters = {
227
- start: "'",
228
- end: "'"
229
- };
230
- this.longFormatters = void 0;
231
- this.date = value => {
232
- if (typeof value === 'undefined') {
233
- return new Date();
234
- }
235
- if (value === null) {
236
- return null;
237
- }
238
- return new Date(value);
239
- };
240
- this.getInvalidDate = () => new Date('Invalid Date');
241
- this.getTimezone = () => {
242
- return 'default';
243
- };
244
- this.setTimezone = value => {
245
- return value;
246
- };
247
- this.toJsDate = value => {
248
- return value;
249
- };
250
- this.getCurrentLocaleCode = () => {
251
- // `code` is undefined only in `date-fns` types, but all locales have it
252
- return this.locale.code;
253
- };
254
- // Note: date-fns input types are more lenient than this adapter, so we need to expose our more
255
- // strict signature and delegate to the more lenient signature. Otherwise, we have downstream type errors upon usage.
256
- this.is12HourCycleInCurrentLocale = () => {
257
- return /a/.test(this.locale.formatLong.time({
258
- width: 'short'
259
- }));
260
- };
261
- this.expandFormat = format => {
262
- const longFormatRegexp = /P+p+|P+|p+|''|'(''|[^'])+('|$)|./g;
263
-
264
- // @see https://github.com/date-fns/date-fns/blob/master/src/format/index.js#L31
265
- return format.match(longFormatRegexp).map(token => {
266
- const firstCharacter = token[0];
267
- if (firstCharacter === 'p' || firstCharacter === 'P') {
268
- const longFormatter = this.longFormatters[firstCharacter];
269
- return longFormatter(token, this.locale.formatLong);
270
- }
271
- return token;
272
- }).join('');
273
- };
274
- this.formatNumber = numberToFormat => {
275
- return numberToFormat;
276
- };
277
- this.getDayOfWeek = value => {
278
- return value.getDay() + 1;
279
- };
280
227
  const {
281
228
  locale,
282
229
  formats,
@@ -288,4 +235,54 @@ export class AdapterDateFnsBase {
288
235
  this.longFormatters = longFormatters;
289
236
  this.lib = lib || 'date-fns';
290
237
  }
238
+ date = value => {
239
+ if (typeof value === 'undefined') {
240
+ return new Date();
241
+ }
242
+ if (value === null) {
243
+ return null;
244
+ }
245
+ return new Date(value);
246
+ };
247
+ getInvalidDate = () => new Date('Invalid Date');
248
+ getTimezone = () => {
249
+ return 'default';
250
+ };
251
+ setTimezone = value => {
252
+ return value;
253
+ };
254
+ toJsDate = value => {
255
+ return value;
256
+ };
257
+ getCurrentLocaleCode = () => {
258
+ // `code` is undefined only in `date-fns` types, but all locales have it
259
+ return this.locale.code;
260
+ };
261
+
262
+ // Note: date-fns input types are more lenient than this adapter, so we need to expose our more
263
+ // strict signature and delegate to the more lenient signature. Otherwise, we have downstream type errors upon usage.
264
+ is12HourCycleInCurrentLocale = () => {
265
+ return /a/.test(this.locale.formatLong.time({
266
+ width: 'short'
267
+ }));
268
+ };
269
+ expandFormat = format => {
270
+ const longFormatRegexp = /P+p+|P+|p+|''|'(''|[^'])+('|$)|./g;
271
+
272
+ // @see https://github.com/date-fns/date-fns/blob/master/src/format/index.js#L31
273
+ return format.match(longFormatRegexp).map(token => {
274
+ const firstCharacter = token[0];
275
+ if (firstCharacter === 'p' || firstCharacter === 'P') {
276
+ const longFormatter = this.longFormatters[firstCharacter];
277
+ return longFormatter(token, this.locale.formatLong);
278
+ }
279
+ return token;
280
+ }).join('');
281
+ };
282
+ formatNumber = numberToFormat => {
283
+ return numberToFormat;
284
+ };
285
+ getDayOfWeek = value => {
286
+ return value.getDay() + 1;
287
+ };
291
288
  }