@mui/x-date-pickers 8.10.0 → 8.11.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.js +194 -195
- package/AdapterDateFnsBase/AdapterDateFnsBase.js +57 -62
- package/AdapterDateFnsJalali/AdapterDateFnsJalali.js +197 -198
- package/AdapterDateFnsJalaliV2/AdapterDateFnsJalaliV2.js +196 -196
- package/AdapterDateFnsV2/AdapterDateFnsV2.js +193 -193
- package/AdapterDayjs/AdapterDayjs.js +378 -379
- package/AdapterLuxon/AdapterLuxon.js +324 -326
- package/AdapterMoment/AdapterMoment.js +297 -302
- package/AdapterMomentHijri/AdapterMomentHijri.js +78 -78
- package/AdapterMomentJalaali/AdapterMomentJalaali.js +78 -80
- package/CHANGELOG.md +309 -0
- package/PickersTextField/PickersInputBase/PickersInputBase.js +14 -1
- package/PickersTextField/PickersTextField.js +3 -2
- package/esm/AdapterDateFns/AdapterDateFns.js +194 -194
- package/esm/AdapterDateFnsBase/AdapterDateFnsBase.js +57 -62
- package/esm/AdapterDateFnsJalali/AdapterDateFnsJalali.js +197 -197
- package/esm/AdapterDateFnsJalaliV2/AdapterDateFnsJalaliV2.js +196 -196
- package/esm/AdapterDateFnsV2/AdapterDateFnsV2.js +193 -193
- package/esm/AdapterDayjs/AdapterDayjs.js +378 -379
- package/esm/AdapterLuxon/AdapterLuxon.js +324 -325
- package/esm/AdapterMoment/AdapterMoment.js +297 -301
- package/esm/AdapterMomentHijri/AdapterMomentHijri.js +78 -78
- package/esm/AdapterMomentJalaali/AdapterMomentJalaali.js +78 -80
- package/esm/PickersTextField/PickersInputBase/PickersInputBase.js +14 -1
- package/esm/PickersTextField/PickersTextField.js +3 -2
- package/esm/index.js +1 -1
- package/esm/internals/hooks/useField/syncSelectionToDOM.js +3 -1
- package/esm/internals/models/helpers.d.ts +1 -1
- package/esm/models/fields.d.ts +4 -0
- package/index.js +1 -1
- package/internals/hooks/useField/syncSelectionToDOM.js +3 -1
- package/internals/models/helpers.d.ts +1 -1
- package/models/fields.d.ts +4 -0
- package/package.json +15 -16
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import _extends from "@babel/runtime/helpers/esm/extends";
|
|
2
|
-
/* eslint-disable class-methods-use-this */
|
|
3
2
|
/* v8 ignore start */
|
|
4
3
|
import dayjs from 'dayjs';
|
|
5
4
|
// dayjs has no exports field defined
|
|
@@ -151,404 +150,404 @@ const MISSING_TIMEZONE_PLUGIN = ['Missing timezone plugin', 'To be able to use t
|
|
|
151
150
|
* SOFTWARE.
|
|
152
151
|
*/
|
|
153
152
|
export class AdapterDayjs {
|
|
153
|
+
isMUIAdapter = true;
|
|
154
|
+
isTimezoneCompatible = true;
|
|
155
|
+
lib = 'dayjs';
|
|
156
|
+
escapedCharacters = {
|
|
157
|
+
start: '[',
|
|
158
|
+
end: ']'
|
|
159
|
+
};
|
|
160
|
+
formatTokenMap = (() => formatTokenMap)();
|
|
154
161
|
constructor({
|
|
155
|
-
locale
|
|
162
|
+
locale,
|
|
156
163
|
formats
|
|
157
164
|
} = {}) {
|
|
158
|
-
this.
|
|
159
|
-
this.
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
{
|
|
192
|
-
return dayjs.tz.guess();
|
|
193
|
-
}
|
|
194
|
-
default:
|
|
195
|
-
{
|
|
196
|
-
return timezone;
|
|
197
|
-
}
|
|
198
|
-
}
|
|
199
|
-
};
|
|
200
|
-
this.createSystemDate = value => {
|
|
201
|
-
let date;
|
|
202
|
-
if (this.hasUTCPlugin() && this.hasTimezonePlugin()) {
|
|
203
|
-
const timezone = dayjs.tz.guess();
|
|
204
|
-
if (timezone === 'UTC') {
|
|
205
|
-
date = dayjs(value);
|
|
206
|
-
} /* v8 ignore next 3 */else {
|
|
207
|
-
// We can't change the system timezone in the tests
|
|
208
|
-
date = dayjs.tz(value, timezone);
|
|
165
|
+
this.locale = locale;
|
|
166
|
+
this.formats = _extends({}, defaultFormats, formats);
|
|
167
|
+
|
|
168
|
+
// Moved plugins to the constructor to allow for users to use options on the library
|
|
169
|
+
// for reference: https://github.com/mui/mui-x/pull/11151
|
|
170
|
+
dayjs.extend(customParseFormatPlugin);
|
|
171
|
+
}
|
|
172
|
+
setLocaleToValue = value => {
|
|
173
|
+
const expectedLocale = this.getCurrentLocaleCode();
|
|
174
|
+
if (expectedLocale === value.locale()) {
|
|
175
|
+
return value;
|
|
176
|
+
}
|
|
177
|
+
return value.locale(expectedLocale);
|
|
178
|
+
};
|
|
179
|
+
hasUTCPlugin = () => typeof dayjs.utc !== 'undefined';
|
|
180
|
+
hasTimezonePlugin = () => typeof dayjs.tz !== 'undefined';
|
|
181
|
+
isSame = (value, comparing, comparisonTemplate) => {
|
|
182
|
+
const comparingInValueTimezone = this.setTimezone(comparing, this.getTimezone(value));
|
|
183
|
+
return value.format(comparisonTemplate) === comparingInValueTimezone.format(comparisonTemplate);
|
|
184
|
+
};
|
|
185
|
+
|
|
186
|
+
/**
|
|
187
|
+
* Replaces "default" by undefined and "system" by the system timezone before passing it to `dayjs`.
|
|
188
|
+
*/
|
|
189
|
+
cleanTimezone = timezone => {
|
|
190
|
+
switch (timezone) {
|
|
191
|
+
case 'default':
|
|
192
|
+
{
|
|
193
|
+
return undefined;
|
|
194
|
+
}
|
|
195
|
+
case 'system':
|
|
196
|
+
{
|
|
197
|
+
return dayjs.tz.guess();
|
|
209
198
|
}
|
|
210
|
-
|
|
199
|
+
default:
|
|
200
|
+
{
|
|
201
|
+
return timezone;
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
};
|
|
205
|
+
createSystemDate = value => {
|
|
206
|
+
let date;
|
|
207
|
+
if (this.hasUTCPlugin() && this.hasTimezonePlugin()) {
|
|
208
|
+
const timezone = dayjs.tz.guess();
|
|
209
|
+
if (timezone === 'UTC') {
|
|
211
210
|
date = dayjs(value);
|
|
211
|
+
} /* v8 ignore next 3 */else {
|
|
212
|
+
// We can't change the system timezone in the tests
|
|
213
|
+
date = dayjs.tz(value, timezone);
|
|
212
214
|
}
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
215
|
+
} else {
|
|
216
|
+
date = dayjs(value);
|
|
217
|
+
}
|
|
218
|
+
return this.setLocaleToValue(date);
|
|
219
|
+
};
|
|
220
|
+
createUTCDate = value => {
|
|
221
|
+
/* v8 ignore next 3 */
|
|
222
|
+
if (!this.hasUTCPlugin()) {
|
|
223
|
+
throw new Error(MISSING_UTC_PLUGIN);
|
|
224
|
+
}
|
|
225
|
+
return this.setLocaleToValue(dayjs.utc(value));
|
|
226
|
+
};
|
|
227
|
+
createTZDate = (value, timezone) => {
|
|
228
|
+
/* v8 ignore next 3 */
|
|
229
|
+
if (!this.hasUTCPlugin()) {
|
|
230
|
+
throw new Error(MISSING_UTC_PLUGIN);
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
/* v8 ignore next 3 */
|
|
234
|
+
if (!this.hasTimezonePlugin()) {
|
|
235
|
+
throw new Error(MISSING_TIMEZONE_PLUGIN);
|
|
236
|
+
}
|
|
237
|
+
const keepLocalTime = value !== undefined && !value.endsWith('Z');
|
|
238
|
+
return this.setLocaleToValue(dayjs(value).tz(this.cleanTimezone(timezone), keepLocalTime));
|
|
239
|
+
};
|
|
240
|
+
getLocaleFormats = () => {
|
|
241
|
+
const locales = dayjs.Ls;
|
|
242
|
+
const locale = this.locale || 'en';
|
|
243
|
+
let localeObject = locales[locale];
|
|
244
|
+
if (localeObject === undefined) {
|
|
245
|
+
/* v8 ignore start */
|
|
246
|
+
if (process.env.NODE_ENV !== 'production') {
|
|
247
|
+
warnOnce(['MUI X: Your locale has not been found.', 'Either the locale key is not a supported one. Locales supported by dayjs are available here: https://github.com/iamkun/dayjs/tree/dev/src/locale.', "Or you forget to import the locale from 'dayjs/locale/{localeUsed}'", 'fallback on English locale.']);
|
|
226
248
|
}
|
|
249
|
+
/* v8 ignore stop */
|
|
250
|
+
localeObject = locales.en;
|
|
251
|
+
}
|
|
252
|
+
return localeObject.formats;
|
|
253
|
+
};
|
|
227
254
|
|
|
255
|
+
/**
|
|
256
|
+
* If the new day does not have the same offset as the old one (when switching to summer day time for example),
|
|
257
|
+
* Then dayjs will not automatically adjust the offset (moment does).
|
|
258
|
+
* We have to parse again the value to make sure the `fixOffset` method is applied.
|
|
259
|
+
* See https://github.com/iamkun/dayjs/blob/b3624de619d6e734cd0ffdbbd3502185041c1b60/src/plugin/timezone/index.js#L72
|
|
260
|
+
*/
|
|
261
|
+
adjustOffset = value => {
|
|
262
|
+
if (!this.hasTimezonePlugin()) {
|
|
263
|
+
return value;
|
|
264
|
+
}
|
|
265
|
+
const timezone = this.getTimezone(value);
|
|
266
|
+
if (timezone !== 'UTC') {
|
|
267
|
+
const fixedValue = value.tz(this.cleanTimezone(timezone), true);
|
|
268
|
+
// TODO: Simplify the case when we raise the `dayjs` peer dep to 1.11.12 (https://github.com/iamkun/dayjs/releases/tag/v1.11.12)
|
|
228
269
|
/* v8 ignore next 3 */
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
}
|
|
232
|
-
const keepLocalTime = value !== undefined && !value.endsWith('Z');
|
|
233
|
-
return this.setLocaleToValue(dayjs(value).tz(this.cleanTimezone(timezone), keepLocalTime));
|
|
234
|
-
};
|
|
235
|
-
this.getLocaleFormats = () => {
|
|
236
|
-
const locales = dayjs.Ls;
|
|
237
|
-
const locale = this.locale || 'en';
|
|
238
|
-
let localeObject = locales[locale];
|
|
239
|
-
if (localeObject === undefined) {
|
|
240
|
-
/* v8 ignore start */
|
|
241
|
-
if (process.env.NODE_ENV !== 'production') {
|
|
242
|
-
warnOnce(['MUI X: Your locale has not been found.', 'Either the locale key is not a supported one. Locales supported by dayjs are available here: https://github.com/iamkun/dayjs/tree/dev/src/locale.', "Or you forget to import the locale from 'dayjs/locale/{localeUsed}'", 'fallback on English locale.']);
|
|
243
|
-
}
|
|
244
|
-
/* v8 ignore stop */
|
|
245
|
-
localeObject = locales.en;
|
|
246
|
-
}
|
|
247
|
-
return localeObject.formats;
|
|
248
|
-
};
|
|
249
|
-
/**
|
|
250
|
-
* If the new day does not have the same offset as the old one (when switching to summer day time for example),
|
|
251
|
-
* Then dayjs will not automatically adjust the offset (moment does).
|
|
252
|
-
* We have to parse again the value to make sure the `fixOffset` method is applied.
|
|
253
|
-
* See https://github.com/iamkun/dayjs/blob/b3624de619d6e734cd0ffdbbd3502185041c1b60/src/plugin/timezone/index.js#L72
|
|
254
|
-
*/
|
|
255
|
-
this.adjustOffset = value => {
|
|
256
|
-
if (!this.hasTimezonePlugin()) {
|
|
270
|
+
// @ts-ignore
|
|
271
|
+
if (fixedValue.$offset === (value.$offset ?? 0)) {
|
|
257
272
|
return value;
|
|
258
273
|
}
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
274
|
+
// Change only what is needed to avoid creating a new object with unwanted data
|
|
275
|
+
// Especially important when used in an environment where utc or timezone dates are used only in some places
|
|
276
|
+
// Reference: https://github.com/mui/mui-x/issues/13290
|
|
277
|
+
// @ts-ignore
|
|
278
|
+
value.$offset = fixedValue.$offset;
|
|
279
|
+
}
|
|
280
|
+
return value;
|
|
281
|
+
};
|
|
282
|
+
date = (value, timezone = 'default') => {
|
|
283
|
+
if (value === null) {
|
|
284
|
+
return null;
|
|
285
|
+
}
|
|
286
|
+
if (timezone === 'UTC') {
|
|
287
|
+
return this.createUTCDate(value);
|
|
288
|
+
}
|
|
289
|
+
if (timezone === 'system' || timezone === 'default' && !this.hasTimezonePlugin()) {
|
|
290
|
+
return this.createSystemDate(value);
|
|
291
|
+
}
|
|
292
|
+
return this.createTZDate(value, timezone);
|
|
293
|
+
};
|
|
294
|
+
getInvalidDate = () => dayjs(new Date('Invalid date'));
|
|
295
|
+
getTimezone = value => {
|
|
296
|
+
if (this.hasTimezonePlugin()) {
|
|
297
|
+
// @ts-ignore
|
|
298
|
+
const zone = value.$x?.$timezone;
|
|
299
|
+
if (zone) {
|
|
300
|
+
return zone;
|
|
273
301
|
}
|
|
302
|
+
}
|
|
303
|
+
if (this.hasUTCPlugin() && value.isUTC()) {
|
|
304
|
+
return 'UTC';
|
|
305
|
+
}
|
|
306
|
+
return 'system';
|
|
307
|
+
};
|
|
308
|
+
setTimezone = (value, timezone) => {
|
|
309
|
+
if (this.getTimezone(value) === timezone) {
|
|
274
310
|
return value;
|
|
275
|
-
}
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
if (timezone === 'UTC') {
|
|
281
|
-
return this.createUTCDate(value);
|
|
282
|
-
}
|
|
283
|
-
if (timezone === 'system' || timezone === 'default' && !this.hasTimezonePlugin()) {
|
|
284
|
-
return this.createSystemDate(value);
|
|
285
|
-
}
|
|
286
|
-
return this.createTZDate(value, timezone);
|
|
287
|
-
};
|
|
288
|
-
this.getInvalidDate = () => dayjs(new Date('Invalid date'));
|
|
289
|
-
this.getTimezone = value => {
|
|
290
|
-
if (this.hasTimezonePlugin()) {
|
|
291
|
-
// @ts-ignore
|
|
292
|
-
const zone = value.$x?.$timezone;
|
|
293
|
-
if (zone) {
|
|
294
|
-
return zone;
|
|
295
|
-
}
|
|
296
|
-
}
|
|
297
|
-
if (this.hasUTCPlugin() && value.isUTC()) {
|
|
298
|
-
return 'UTC';
|
|
299
|
-
}
|
|
300
|
-
return 'system';
|
|
301
|
-
};
|
|
302
|
-
this.setTimezone = (value, timezone) => {
|
|
303
|
-
if (this.getTimezone(value) === timezone) {
|
|
304
|
-
return value;
|
|
305
|
-
}
|
|
306
|
-
if (timezone === 'UTC') {
|
|
307
|
-
/* v8 ignore next 3 */
|
|
308
|
-
if (!this.hasUTCPlugin()) {
|
|
309
|
-
throw new Error(MISSING_UTC_PLUGIN);
|
|
310
|
-
}
|
|
311
|
-
return value.utc();
|
|
311
|
+
}
|
|
312
|
+
if (timezone === 'UTC') {
|
|
313
|
+
/* v8 ignore next 3 */
|
|
314
|
+
if (!this.hasUTCPlugin()) {
|
|
315
|
+
throw new Error(MISSING_UTC_PLUGIN);
|
|
312
316
|
}
|
|
317
|
+
return value.utc();
|
|
318
|
+
}
|
|
313
319
|
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
320
|
+
// We know that we have the UTC plugin.
|
|
321
|
+
// Otherwise, the value timezone would always equal "system".
|
|
322
|
+
// And it would be caught by the first "if" of this method.
|
|
323
|
+
if (timezone === 'system') {
|
|
324
|
+
return value.local();
|
|
325
|
+
}
|
|
326
|
+
if (!this.hasTimezonePlugin()) {
|
|
327
|
+
if (timezone === 'default') {
|
|
328
|
+
return value;
|
|
319
329
|
}
|
|
320
|
-
if (!this.hasTimezonePlugin()) {
|
|
321
|
-
if (timezone === 'default') {
|
|
322
|
-
return value;
|
|
323
|
-
}
|
|
324
330
|
|
|
325
|
-
/* v8 ignore next */
|
|
326
|
-
throw new Error(MISSING_TIMEZONE_PLUGIN);
|
|
327
|
-
}
|
|
328
|
-
return this.setLocaleToValue(dayjs.tz(value, this.cleanTimezone(timezone)));
|
|
329
|
-
};
|
|
330
|
-
this.toJsDate = value => {
|
|
331
|
-
return value.toDate();
|
|
332
|
-
};
|
|
333
|
-
this.parse = (value, format) => {
|
|
334
|
-
if (value === '') {
|
|
335
|
-
return null;
|
|
336
|
-
}
|
|
337
|
-
return dayjs(value, format, this.locale, true);
|
|
338
|
-
};
|
|
339
|
-
this.getCurrentLocaleCode = () => {
|
|
340
|
-
return this.locale || 'en';
|
|
341
|
-
};
|
|
342
|
-
this.is12HourCycleInCurrentLocale = () => {
|
|
343
331
|
/* v8 ignore next */
|
|
344
|
-
|
|
345
|
-
}
|
|
346
|
-
this.
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
this.
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
return this.setLocaleToValue(value).format(formatString);
|
|
367
|
-
};
|
|
368
|
-
this.formatNumber = numberToFormat => {
|
|
369
|
-
return numberToFormat;
|
|
370
|
-
};
|
|
371
|
-
this.isEqual = (value, comparing) => {
|
|
372
|
-
if (value === null && comparing === null) {
|
|
373
|
-
return true;
|
|
374
|
-
}
|
|
375
|
-
if (value === null || comparing === null) {
|
|
376
|
-
return false;
|
|
377
|
-
}
|
|
378
|
-
return value.toDate().getTime() === comparing.toDate().getTime();
|
|
379
|
-
};
|
|
380
|
-
this.isSameYear = (value, comparing) => {
|
|
381
|
-
return this.isSame(value, comparing, 'YYYY');
|
|
382
|
-
};
|
|
383
|
-
this.isSameMonth = (value, comparing) => {
|
|
384
|
-
return this.isSame(value, comparing, 'YYYY-MM');
|
|
385
|
-
};
|
|
386
|
-
this.isSameDay = (value, comparing) => {
|
|
387
|
-
return this.isSame(value, comparing, 'YYYY-MM-DD');
|
|
388
|
-
};
|
|
389
|
-
this.isSameHour = (value, comparing) => {
|
|
390
|
-
return value.isSame(comparing, 'hour');
|
|
391
|
-
};
|
|
392
|
-
this.isAfter = (value, comparing) => {
|
|
393
|
-
return value > comparing;
|
|
394
|
-
};
|
|
395
|
-
this.isAfterYear = (value, comparing) => {
|
|
396
|
-
if (!this.hasUTCPlugin()) {
|
|
397
|
-
return value.isAfter(comparing, 'year');
|
|
398
|
-
}
|
|
399
|
-
return !this.isSameYear(value, comparing) && value.utc() > comparing.utc();
|
|
400
|
-
};
|
|
401
|
-
this.isAfterDay = (value, comparing) => {
|
|
402
|
-
if (!this.hasUTCPlugin()) {
|
|
403
|
-
return value.isAfter(comparing, 'day');
|
|
404
|
-
}
|
|
405
|
-
return !this.isSameDay(value, comparing) && value.utc() > comparing.utc();
|
|
406
|
-
};
|
|
407
|
-
this.isBefore = (value, comparing) => {
|
|
408
|
-
return value < comparing;
|
|
409
|
-
};
|
|
410
|
-
this.isBeforeYear = (value, comparing) => {
|
|
411
|
-
if (!this.hasUTCPlugin()) {
|
|
412
|
-
return value.isBefore(comparing, 'year');
|
|
413
|
-
}
|
|
414
|
-
return !this.isSameYear(value, comparing) && value.utc() < comparing.utc();
|
|
415
|
-
};
|
|
416
|
-
this.isBeforeDay = (value, comparing) => {
|
|
417
|
-
if (!this.hasUTCPlugin()) {
|
|
418
|
-
return value.isBefore(comparing, 'day');
|
|
419
|
-
}
|
|
420
|
-
return !this.isSameDay(value, comparing) && value.utc() < comparing.utc();
|
|
421
|
-
};
|
|
422
|
-
this.isWithinRange = (value, [start, end]) => {
|
|
423
|
-
return value >= start && value <= end;
|
|
424
|
-
};
|
|
425
|
-
this.startOfYear = value => {
|
|
426
|
-
return this.adjustOffset(value.startOf('year'));
|
|
427
|
-
};
|
|
428
|
-
this.startOfMonth = value => {
|
|
429
|
-
return this.adjustOffset(value.startOf('month'));
|
|
430
|
-
};
|
|
431
|
-
this.startOfWeek = value => {
|
|
432
|
-
return this.adjustOffset(this.setLocaleToValue(value).startOf('week'));
|
|
433
|
-
};
|
|
434
|
-
this.startOfDay = value => {
|
|
435
|
-
return this.adjustOffset(value.startOf('day'));
|
|
436
|
-
};
|
|
437
|
-
this.endOfYear = value => {
|
|
438
|
-
return this.adjustOffset(value.endOf('year'));
|
|
439
|
-
};
|
|
440
|
-
this.endOfMonth = value => {
|
|
441
|
-
return this.adjustOffset(value.endOf('month'));
|
|
442
|
-
};
|
|
443
|
-
this.endOfWeek = value => {
|
|
444
|
-
return this.adjustOffset(this.setLocaleToValue(value).endOf('week'));
|
|
445
|
-
};
|
|
446
|
-
this.endOfDay = value => {
|
|
447
|
-
return this.adjustOffset(value.endOf('day'));
|
|
448
|
-
};
|
|
449
|
-
this.addYears = (value, amount) => {
|
|
450
|
-
return this.adjustOffset(value.add(amount, 'year'));
|
|
451
|
-
};
|
|
452
|
-
this.addMonths = (value, amount) => {
|
|
453
|
-
return this.adjustOffset(value.add(amount, 'month'));
|
|
454
|
-
};
|
|
455
|
-
this.addWeeks = (value, amount) => {
|
|
456
|
-
return this.adjustOffset(value.add(amount, 'week'));
|
|
457
|
-
};
|
|
458
|
-
this.addDays = (value, amount) => {
|
|
459
|
-
return this.adjustOffset(value.add(amount, 'day'));
|
|
460
|
-
};
|
|
461
|
-
this.addHours = (value, amount) => {
|
|
462
|
-
return this.adjustOffset(value.add(amount, 'hour'));
|
|
463
|
-
};
|
|
464
|
-
this.addMinutes = (value, amount) => {
|
|
465
|
-
return this.adjustOffset(value.add(amount, 'minute'));
|
|
466
|
-
};
|
|
467
|
-
this.addSeconds = (value, amount) => {
|
|
468
|
-
return this.adjustOffset(value.add(amount, 'second'));
|
|
469
|
-
};
|
|
470
|
-
this.getYear = value => {
|
|
471
|
-
return value.year();
|
|
472
|
-
};
|
|
473
|
-
this.getMonth = value => {
|
|
474
|
-
return value.month();
|
|
475
|
-
};
|
|
476
|
-
this.getDate = value => {
|
|
477
|
-
return value.date();
|
|
478
|
-
};
|
|
479
|
-
this.getHours = value => {
|
|
480
|
-
return value.hour();
|
|
481
|
-
};
|
|
482
|
-
this.getMinutes = value => {
|
|
483
|
-
return value.minute();
|
|
484
|
-
};
|
|
485
|
-
this.getSeconds = value => {
|
|
486
|
-
return value.second();
|
|
487
|
-
};
|
|
488
|
-
this.getMilliseconds = value => {
|
|
489
|
-
return value.millisecond();
|
|
490
|
-
};
|
|
491
|
-
this.setYear = (value, year) => {
|
|
492
|
-
return this.adjustOffset(value.set('year', year));
|
|
493
|
-
};
|
|
494
|
-
this.setMonth = (value, month) => {
|
|
495
|
-
return this.adjustOffset(value.set('month', month));
|
|
496
|
-
};
|
|
497
|
-
this.setDate = (value, date) => {
|
|
498
|
-
return this.adjustOffset(value.set('date', date));
|
|
499
|
-
};
|
|
500
|
-
this.setHours = (value, hours) => {
|
|
501
|
-
return this.adjustOffset(value.set('hour', hours));
|
|
502
|
-
};
|
|
503
|
-
this.setMinutes = (value, minutes) => {
|
|
504
|
-
return this.adjustOffset(value.set('minute', minutes));
|
|
505
|
-
};
|
|
506
|
-
this.setSeconds = (value, seconds) => {
|
|
507
|
-
return this.adjustOffset(value.set('second', seconds));
|
|
508
|
-
};
|
|
509
|
-
this.setMilliseconds = (value, milliseconds) => {
|
|
510
|
-
return this.adjustOffset(value.set('millisecond', milliseconds));
|
|
511
|
-
};
|
|
512
|
-
this.getDaysInMonth = value => {
|
|
513
|
-
return value.daysInMonth();
|
|
514
|
-
};
|
|
515
|
-
this.getWeekArray = value => {
|
|
516
|
-
const start = this.startOfWeek(this.startOfMonth(value));
|
|
517
|
-
const end = this.endOfWeek(this.endOfMonth(value));
|
|
518
|
-
let count = 0;
|
|
519
|
-
let current = start;
|
|
520
|
-
const nestedWeeks = [];
|
|
521
|
-
while (current < end) {
|
|
522
|
-
const weekNumber = Math.floor(count / 7);
|
|
523
|
-
nestedWeeks[weekNumber] = nestedWeeks[weekNumber] || [];
|
|
524
|
-
nestedWeeks[weekNumber].push(current);
|
|
525
|
-
current = this.addDays(current, 1);
|
|
526
|
-
count += 1;
|
|
527
|
-
}
|
|
528
|
-
return nestedWeeks;
|
|
529
|
-
};
|
|
530
|
-
this.getWeekNumber = value => {
|
|
531
|
-
return value.week();
|
|
532
|
-
};
|
|
533
|
-
this.getYearRange = ([start, end]) => {
|
|
534
|
-
const startDate = this.startOfYear(start);
|
|
535
|
-
const endDate = this.endOfYear(end);
|
|
536
|
-
const years = [];
|
|
537
|
-
let current = startDate;
|
|
538
|
-
while (this.isBefore(current, endDate)) {
|
|
539
|
-
years.push(current);
|
|
540
|
-
current = this.addYears(current, 1);
|
|
541
|
-
}
|
|
542
|
-
return years;
|
|
543
|
-
};
|
|
544
|
-
this.locale = _locale;
|
|
545
|
-
this.formats = _extends({}, defaultFormats, formats);
|
|
332
|
+
throw new Error(MISSING_TIMEZONE_PLUGIN);
|
|
333
|
+
}
|
|
334
|
+
return this.setLocaleToValue(dayjs.tz(value, this.cleanTimezone(timezone)));
|
|
335
|
+
};
|
|
336
|
+
toJsDate = value => {
|
|
337
|
+
return value.toDate();
|
|
338
|
+
};
|
|
339
|
+
parse = (value, format) => {
|
|
340
|
+
if (value === '') {
|
|
341
|
+
return null;
|
|
342
|
+
}
|
|
343
|
+
return dayjs(value, format, this.locale, true);
|
|
344
|
+
};
|
|
345
|
+
getCurrentLocaleCode = () => {
|
|
346
|
+
return this.locale || 'en';
|
|
347
|
+
};
|
|
348
|
+
is12HourCycleInCurrentLocale = () => {
|
|
349
|
+
/* v8 ignore next */
|
|
350
|
+
return /A|a/.test(this.getLocaleFormats().LT || '');
|
|
351
|
+
};
|
|
352
|
+
expandFormat = format => {
|
|
353
|
+
const localeFormats = this.getLocaleFormats();
|
|
546
354
|
|
|
547
|
-
//
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
355
|
+
// @see https://github.com/iamkun/dayjs/blob/dev/src/plugin/localizedFormat/index.js
|
|
356
|
+
const t = formatBis => formatBis.replace(/(\[[^\]]+])|(MMMM|MM|DD|dddd)/g, (_, a, b) => a || b.slice(1));
|
|
357
|
+
return format.replace(/(\[[^\]]+])|(LTS?|l{1,4}|L{1,4})/g, (_, a, b) => {
|
|
358
|
+
const B = b && b.toUpperCase();
|
|
359
|
+
return a || localeFormats[b] || t(localeFormats[B]);
|
|
360
|
+
});
|
|
361
|
+
};
|
|
362
|
+
isValid = value => {
|
|
363
|
+
if (value == null) {
|
|
364
|
+
return false;
|
|
365
|
+
}
|
|
366
|
+
return value.isValid();
|
|
367
|
+
};
|
|
368
|
+
format = (value, formatKey) => {
|
|
369
|
+
return this.formatByString(value, this.formats[formatKey]);
|
|
370
|
+
};
|
|
371
|
+
formatByString = (value, formatString) => {
|
|
372
|
+
return this.setLocaleToValue(value).format(formatString);
|
|
373
|
+
};
|
|
374
|
+
formatNumber = numberToFormat => {
|
|
375
|
+
return numberToFormat;
|
|
376
|
+
};
|
|
377
|
+
isEqual = (value, comparing) => {
|
|
378
|
+
if (value === null && comparing === null) {
|
|
379
|
+
return true;
|
|
380
|
+
}
|
|
381
|
+
if (value === null || comparing === null) {
|
|
382
|
+
return false;
|
|
383
|
+
}
|
|
384
|
+
return value.toDate().getTime() === comparing.toDate().getTime();
|
|
385
|
+
};
|
|
386
|
+
isSameYear = (value, comparing) => {
|
|
387
|
+
return this.isSame(value, comparing, 'YYYY');
|
|
388
|
+
};
|
|
389
|
+
isSameMonth = (value, comparing) => {
|
|
390
|
+
return this.isSame(value, comparing, 'YYYY-MM');
|
|
391
|
+
};
|
|
392
|
+
isSameDay = (value, comparing) => {
|
|
393
|
+
return this.isSame(value, comparing, 'YYYY-MM-DD');
|
|
394
|
+
};
|
|
395
|
+
isSameHour = (value, comparing) => {
|
|
396
|
+
return value.isSame(comparing, 'hour');
|
|
397
|
+
};
|
|
398
|
+
isAfter = (value, comparing) => {
|
|
399
|
+
return value > comparing;
|
|
400
|
+
};
|
|
401
|
+
isAfterYear = (value, comparing) => {
|
|
402
|
+
if (!this.hasUTCPlugin()) {
|
|
403
|
+
return value.isAfter(comparing, 'year');
|
|
404
|
+
}
|
|
405
|
+
return !this.isSameYear(value, comparing) && value.utc() > comparing.utc();
|
|
406
|
+
};
|
|
407
|
+
isAfterDay = (value, comparing) => {
|
|
408
|
+
if (!this.hasUTCPlugin()) {
|
|
409
|
+
return value.isAfter(comparing, 'day');
|
|
410
|
+
}
|
|
411
|
+
return !this.isSameDay(value, comparing) && value.utc() > comparing.utc();
|
|
412
|
+
};
|
|
413
|
+
isBefore = (value, comparing) => {
|
|
414
|
+
return value < comparing;
|
|
415
|
+
};
|
|
416
|
+
isBeforeYear = (value, comparing) => {
|
|
417
|
+
if (!this.hasUTCPlugin()) {
|
|
418
|
+
return value.isBefore(comparing, 'year');
|
|
419
|
+
}
|
|
420
|
+
return !this.isSameYear(value, comparing) && value.utc() < comparing.utc();
|
|
421
|
+
};
|
|
422
|
+
isBeforeDay = (value, comparing) => {
|
|
423
|
+
if (!this.hasUTCPlugin()) {
|
|
424
|
+
return value.isBefore(comparing, 'day');
|
|
425
|
+
}
|
|
426
|
+
return !this.isSameDay(value, comparing) && value.utc() < comparing.utc();
|
|
427
|
+
};
|
|
428
|
+
isWithinRange = (value, [start, end]) => {
|
|
429
|
+
return value >= start && value <= end;
|
|
430
|
+
};
|
|
431
|
+
startOfYear = value => {
|
|
432
|
+
return this.adjustOffset(value.startOf('year'));
|
|
433
|
+
};
|
|
434
|
+
startOfMonth = value => {
|
|
435
|
+
return this.adjustOffset(value.startOf('month'));
|
|
436
|
+
};
|
|
437
|
+
startOfWeek = value => {
|
|
438
|
+
return this.adjustOffset(this.setLocaleToValue(value).startOf('week'));
|
|
439
|
+
};
|
|
440
|
+
startOfDay = value => {
|
|
441
|
+
return this.adjustOffset(value.startOf('day'));
|
|
442
|
+
};
|
|
443
|
+
endOfYear = value => {
|
|
444
|
+
return this.adjustOffset(value.endOf('year'));
|
|
445
|
+
};
|
|
446
|
+
endOfMonth = value => {
|
|
447
|
+
return this.adjustOffset(value.endOf('month'));
|
|
448
|
+
};
|
|
449
|
+
endOfWeek = value => {
|
|
450
|
+
return this.adjustOffset(this.setLocaleToValue(value).endOf('week'));
|
|
451
|
+
};
|
|
452
|
+
endOfDay = value => {
|
|
453
|
+
return this.adjustOffset(value.endOf('day'));
|
|
454
|
+
};
|
|
455
|
+
addYears = (value, amount) => {
|
|
456
|
+
return this.adjustOffset(value.add(amount, 'year'));
|
|
457
|
+
};
|
|
458
|
+
addMonths = (value, amount) => {
|
|
459
|
+
return this.adjustOffset(value.add(amount, 'month'));
|
|
460
|
+
};
|
|
461
|
+
addWeeks = (value, amount) => {
|
|
462
|
+
return this.adjustOffset(value.add(amount, 'week'));
|
|
463
|
+
};
|
|
464
|
+
addDays = (value, amount) => {
|
|
465
|
+
return this.adjustOffset(value.add(amount, 'day'));
|
|
466
|
+
};
|
|
467
|
+
addHours = (value, amount) => {
|
|
468
|
+
return this.adjustOffset(value.add(amount, 'hour'));
|
|
469
|
+
};
|
|
470
|
+
addMinutes = (value, amount) => {
|
|
471
|
+
return this.adjustOffset(value.add(amount, 'minute'));
|
|
472
|
+
};
|
|
473
|
+
addSeconds = (value, amount) => {
|
|
474
|
+
return this.adjustOffset(value.add(amount, 'second'));
|
|
475
|
+
};
|
|
476
|
+
getYear = value => {
|
|
477
|
+
return value.year();
|
|
478
|
+
};
|
|
479
|
+
getMonth = value => {
|
|
480
|
+
return value.month();
|
|
481
|
+
};
|
|
482
|
+
getDate = value => {
|
|
483
|
+
return value.date();
|
|
484
|
+
};
|
|
485
|
+
getHours = value => {
|
|
486
|
+
return value.hour();
|
|
487
|
+
};
|
|
488
|
+
getMinutes = value => {
|
|
489
|
+
return value.minute();
|
|
490
|
+
};
|
|
491
|
+
getSeconds = value => {
|
|
492
|
+
return value.second();
|
|
493
|
+
};
|
|
494
|
+
getMilliseconds = value => {
|
|
495
|
+
return value.millisecond();
|
|
496
|
+
};
|
|
497
|
+
setYear = (value, year) => {
|
|
498
|
+
return this.adjustOffset(value.set('year', year));
|
|
499
|
+
};
|
|
500
|
+
setMonth = (value, month) => {
|
|
501
|
+
return this.adjustOffset(value.set('month', month));
|
|
502
|
+
};
|
|
503
|
+
setDate = (value, date) => {
|
|
504
|
+
return this.adjustOffset(value.set('date', date));
|
|
505
|
+
};
|
|
506
|
+
setHours = (value, hours) => {
|
|
507
|
+
return this.adjustOffset(value.set('hour', hours));
|
|
508
|
+
};
|
|
509
|
+
setMinutes = (value, minutes) => {
|
|
510
|
+
return this.adjustOffset(value.set('minute', minutes));
|
|
511
|
+
};
|
|
512
|
+
setSeconds = (value, seconds) => {
|
|
513
|
+
return this.adjustOffset(value.set('second', seconds));
|
|
514
|
+
};
|
|
515
|
+
setMilliseconds = (value, milliseconds) => {
|
|
516
|
+
return this.adjustOffset(value.set('millisecond', milliseconds));
|
|
517
|
+
};
|
|
518
|
+
getDaysInMonth = value => {
|
|
519
|
+
return value.daysInMonth();
|
|
520
|
+
};
|
|
521
|
+
getWeekArray = value => {
|
|
522
|
+
const start = this.startOfWeek(this.startOfMonth(value));
|
|
523
|
+
const end = this.endOfWeek(this.endOfMonth(value));
|
|
524
|
+
let count = 0;
|
|
525
|
+
let current = start;
|
|
526
|
+
const nestedWeeks = [];
|
|
527
|
+
while (current < end) {
|
|
528
|
+
const weekNumber = Math.floor(count / 7);
|
|
529
|
+
nestedWeeks[weekNumber] = nestedWeeks[weekNumber] || [];
|
|
530
|
+
nestedWeeks[weekNumber].push(current);
|
|
531
|
+
current = this.addDays(current, 1);
|
|
532
|
+
count += 1;
|
|
533
|
+
}
|
|
534
|
+
return nestedWeeks;
|
|
535
|
+
};
|
|
536
|
+
getWeekNumber = value => {
|
|
537
|
+
return value.week();
|
|
538
|
+
};
|
|
551
539
|
getDayOfWeek(value) {
|
|
552
540
|
return value.day() + 1;
|
|
553
541
|
}
|
|
542
|
+
getYearRange = ([start, end]) => {
|
|
543
|
+
const startDate = this.startOfYear(start);
|
|
544
|
+
const endDate = this.endOfYear(end);
|
|
545
|
+
const years = [];
|
|
546
|
+
let current = startDate;
|
|
547
|
+
while (this.isBefore(current, endDate)) {
|
|
548
|
+
years.push(current);
|
|
549
|
+
current = this.addYears(current, 1);
|
|
550
|
+
}
|
|
551
|
+
return years;
|
|
552
|
+
};
|
|
554
553
|
}
|