@mui/x-date-pickers 8.9.2 → 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.
- package/AdapterDateFns/AdapterDateFns.js +194 -193
- package/AdapterDateFnsBase/AdapterDateFnsBase.js +57 -60
- package/AdapterDateFnsJalali/AdapterDateFnsJalali.js +197 -196
- package/AdapterDateFnsJalaliV2/AdapterDateFnsJalaliV2.js +195 -195
- package/AdapterDateFnsV2/AdapterDateFnsV2.js +192 -192
- package/AdapterDayjs/AdapterDayjs.js +378 -378
- package/AdapterLuxon/AdapterLuxon.js +324 -324
- package/AdapterMoment/AdapterMoment.js +297 -300
- package/AdapterMomentHijri/AdapterMomentHijri.js +78 -77
- package/AdapterMomentJalaali/AdapterMomentJalaali.js +78 -79
- package/CHANGELOG.md +303 -6
- package/PickersLayout/PickersLayout.js +12 -9
- package/PickersLayout/PickersLayout.types.d.ts +5 -0
- package/PickersLayout/usePickerLayout.js +6 -2
- package/esm/AdapterDateFns/AdapterDateFns.js +194 -193
- package/esm/AdapterDateFnsBase/AdapterDateFnsBase.js +57 -60
- package/esm/AdapterDateFnsJalali/AdapterDateFnsJalali.js +197 -196
- package/esm/AdapterDateFnsJalaliV2/AdapterDateFnsJalaliV2.js +195 -195
- package/esm/AdapterDateFnsV2/AdapterDateFnsV2.js +192 -192
- package/esm/AdapterDayjs/AdapterDayjs.js +378 -378
- package/esm/AdapterLuxon/AdapterLuxon.js +324 -324
- package/esm/AdapterMoment/AdapterMoment.js +297 -300
- package/esm/AdapterMomentHijri/AdapterMomentHijri.js +78 -77
- package/esm/AdapterMomentJalaali/AdapterMomentJalaali.js +78 -79
- package/esm/PickersLayout/PickersLayout.js +12 -9
- package/esm/PickersLayout/PickersLayout.types.d.ts +5 -0
- package/esm/PickersLayout/usePickerLayout.js +6 -2
- package/esm/index.js +1 -1
- package/index.js +1 -1
- package/package.json +7 -9
|
@@ -158,344 +158,344 @@ const defaultFormats = {
|
|
|
158
158
|
* SOFTWARE.
|
|
159
159
|
*/
|
|
160
160
|
export class AdapterLuxon {
|
|
161
|
+
isMUIAdapter = true;
|
|
162
|
+
isTimezoneCompatible = true;
|
|
163
|
+
lib = 'luxon';
|
|
164
|
+
escapedCharacters = {
|
|
165
|
+
start: "'",
|
|
166
|
+
end: "'"
|
|
167
|
+
};
|
|
168
|
+
formatTokenMap = (() => formatTokenMap)();
|
|
161
169
|
constructor({
|
|
162
170
|
locale,
|
|
163
171
|
formats
|
|
164
172
|
} = {}) {
|
|
165
|
-
this.
|
|
166
|
-
this.
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
return value.setLocale(expectedLocale);
|
|
181
|
-
};
|
|
182
|
-
this.date = (value, timezone = 'default') => {
|
|
183
|
-
if (value === null) {
|
|
184
|
-
return null;
|
|
185
|
-
}
|
|
186
|
-
if (typeof value === 'undefined') {
|
|
187
|
-
// @ts-ignore
|
|
188
|
-
return DateTime.fromJSDate(new Date(), {
|
|
189
|
-
locale: this.locale,
|
|
190
|
-
zone: timezone
|
|
191
|
-
});
|
|
192
|
-
}
|
|
193
|
-
|
|
173
|
+
this.locale = locale || 'en-US';
|
|
174
|
+
this.formats = _extends({}, defaultFormats, formats);
|
|
175
|
+
}
|
|
176
|
+
setLocaleToValue = value => {
|
|
177
|
+
const expectedLocale = this.getCurrentLocaleCode();
|
|
178
|
+
if (expectedLocale === value.locale) {
|
|
179
|
+
return value;
|
|
180
|
+
}
|
|
181
|
+
return value.setLocale(expectedLocale);
|
|
182
|
+
};
|
|
183
|
+
date = (value, timezone = 'default') => {
|
|
184
|
+
if (value === null) {
|
|
185
|
+
return null;
|
|
186
|
+
}
|
|
187
|
+
if (typeof value === 'undefined') {
|
|
194
188
|
// @ts-ignore
|
|
195
|
-
return DateTime.
|
|
189
|
+
return DateTime.fromJSDate(new Date(), {
|
|
196
190
|
locale: this.locale,
|
|
197
191
|
zone: timezone
|
|
198
192
|
});
|
|
199
|
-
}
|
|
200
|
-
this.getInvalidDate = () => DateTime.fromJSDate(new Date('Invalid Date'));
|
|
201
|
-
this.getTimezone = value => {
|
|
202
|
-
// When using the system zone, we want to return "system", not something like "Europe/Paris"
|
|
203
|
-
if (value.zone.type === 'system') {
|
|
204
|
-
return 'system';
|
|
205
|
-
}
|
|
206
|
-
return value.zoneName;
|
|
207
|
-
};
|
|
208
|
-
this.setTimezone = (value, timezone) => {
|
|
209
|
-
if (!value.zone.equals(Info.normalizeZone(timezone))) {
|
|
210
|
-
return value.setZone(timezone);
|
|
211
|
-
}
|
|
212
|
-
return value;
|
|
213
|
-
};
|
|
214
|
-
this.toJsDate = value => {
|
|
215
|
-
return value.toJSDate();
|
|
216
|
-
};
|
|
217
|
-
this.parse = (value, formatString) => {
|
|
218
|
-
if (value === '') {
|
|
219
|
-
return null;
|
|
220
|
-
}
|
|
221
|
-
return DateTime.fromFormat(value, formatString, {
|
|
222
|
-
locale: this.locale
|
|
223
|
-
});
|
|
224
|
-
};
|
|
225
|
-
this.getCurrentLocaleCode = () => {
|
|
226
|
-
return this.locale;
|
|
227
|
-
};
|
|
228
|
-
/* v8 ignore start */
|
|
229
|
-
this.is12HourCycleInCurrentLocale = () => {
|
|
230
|
-
if (typeof Intl === 'undefined' || typeof Intl.DateTimeFormat === 'undefined') {
|
|
231
|
-
return true; // Luxon defaults to en-US if Intl not found
|
|
232
|
-
}
|
|
233
|
-
return Boolean(new Intl.DateTimeFormat(this.locale, {
|
|
234
|
-
hour: 'numeric'
|
|
235
|
-
})?.resolvedOptions()?.hour12);
|
|
236
|
-
};
|
|
237
|
-
/* v8 ignore stop */
|
|
238
|
-
this.expandFormat = format => {
|
|
239
|
-
// Extract escaped section to avoid extending them
|
|
240
|
-
const catchEscapedSectionsRegexp = /''|'(''|[^'])+('|$)|[^']*/g;
|
|
193
|
+
}
|
|
241
194
|
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
195
|
+
// @ts-ignore
|
|
196
|
+
return DateTime.fromISO(value, {
|
|
197
|
+
locale: this.locale,
|
|
198
|
+
zone: timezone
|
|
199
|
+
});
|
|
200
|
+
};
|
|
201
|
+
getInvalidDate = () => DateTime.fromJSDate(new Date('Invalid Date'));
|
|
202
|
+
getTimezone = value => {
|
|
203
|
+
// When using the system zone, we want to return "system", not something like "Europe/Paris"
|
|
204
|
+
if (value.zone.type === 'system') {
|
|
205
|
+
return 'system';
|
|
206
|
+
}
|
|
207
|
+
return value.zoneName;
|
|
208
|
+
};
|
|
209
|
+
setTimezone = (value, timezone) => {
|
|
210
|
+
if (!value.zone.equals(Info.normalizeZone(timezone))) {
|
|
211
|
+
return value.setZone(timezone);
|
|
212
|
+
}
|
|
213
|
+
return value;
|
|
214
|
+
};
|
|
215
|
+
toJsDate = value => {
|
|
216
|
+
return value.toJSDate();
|
|
217
|
+
};
|
|
218
|
+
parse = (value, formatString) => {
|
|
219
|
+
if (value === '') {
|
|
220
|
+
return null;
|
|
221
|
+
}
|
|
222
|
+
return DateTime.fromFormat(value, formatString, {
|
|
223
|
+
locale: this.locale
|
|
224
|
+
});
|
|
225
|
+
};
|
|
226
|
+
getCurrentLocaleCode = () => {
|
|
227
|
+
return this.locale;
|
|
228
|
+
};
|
|
245
229
|
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
return expandedToken.replace(catchWordsRegexp, (substring, g1, g2) => {
|
|
257
|
-
const word = g1 || g2; // words are either in group 1 or group 2
|
|
230
|
+
/* v8 ignore start */
|
|
231
|
+
is12HourCycleInCurrentLocale = () => {
|
|
232
|
+
if (typeof Intl === 'undefined' || typeof Intl.DateTimeFormat === 'undefined') {
|
|
233
|
+
return true; // Luxon defaults to en-US if Intl not found
|
|
234
|
+
}
|
|
235
|
+
return Boolean(new Intl.DateTimeFormat(this.locale, {
|
|
236
|
+
hour: 'numeric'
|
|
237
|
+
})?.resolvedOptions()?.hour12);
|
|
238
|
+
};
|
|
239
|
+
/* v8 ignore stop */
|
|
258
240
|
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
if (
|
|
272
|
-
return
|
|
273
|
-
}
|
|
274
|
-
return value.isValid;
|
|
275
|
-
};
|
|
276
|
-
this.format = (value, formatKey) => {
|
|
277
|
-
return this.formatByString(value, this.formats[formatKey]);
|
|
278
|
-
};
|
|
279
|
-
this.formatByString = (value, format) => {
|
|
280
|
-
return value.setLocale(this.locale).toFormat(format);
|
|
281
|
-
};
|
|
282
|
-
this.formatNumber = numberToFormat => {
|
|
283
|
-
return numberToFormat;
|
|
284
|
-
};
|
|
285
|
-
this.isEqual = (value, comparing) => {
|
|
286
|
-
if (value === null && comparing === null) {
|
|
287
|
-
return true;
|
|
288
|
-
}
|
|
289
|
-
if (value === null || comparing === null) {
|
|
290
|
-
return false;
|
|
241
|
+
expandFormat = format => {
|
|
242
|
+
// Extract escaped section to avoid extending them
|
|
243
|
+
const catchEscapedSectionsRegexp = /''|'(''|[^'])+('|$)|[^']*/g;
|
|
244
|
+
|
|
245
|
+
// This RegExp tests if a string is only mad of supported tokens
|
|
246
|
+
const validTokens = [...Object.keys(this.formatTokenMap), 'yyyyy'];
|
|
247
|
+
const isWordComposedOfTokens = new RegExp(`^(${validTokens.join('|')})+$`);
|
|
248
|
+
|
|
249
|
+
// Extract words to test if they are a token or a word to escape.
|
|
250
|
+
const catchWordsRegexp = /(?:^|[^a-z])([a-z]+)(?:[^a-z]|$)|([a-z]+)/gi;
|
|
251
|
+
return format.match(catchEscapedSectionsRegexp).map(token => {
|
|
252
|
+
const firstCharacter = token[0];
|
|
253
|
+
if (firstCharacter === "'") {
|
|
254
|
+
return token;
|
|
291
255
|
}
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
this.isSameYear = (value, comparing) => {
|
|
295
|
-
const comparingInValueTimezone = this.setTimezone(comparing, this.getTimezone(value));
|
|
296
|
-
return value.hasSame(comparingInValueTimezone, 'year');
|
|
297
|
-
};
|
|
298
|
-
this.isSameMonth = (value, comparing) => {
|
|
299
|
-
const comparingInValueTimezone = this.setTimezone(comparing, this.getTimezone(value));
|
|
300
|
-
return value.hasSame(comparingInValueTimezone, 'month');
|
|
301
|
-
};
|
|
302
|
-
this.isSameDay = (value, comparing) => {
|
|
303
|
-
const comparingInValueTimezone = this.setTimezone(comparing, this.getTimezone(value));
|
|
304
|
-
return value.hasSame(comparingInValueTimezone, 'day');
|
|
305
|
-
};
|
|
306
|
-
this.isSameHour = (value, comparing) => {
|
|
307
|
-
const comparingInValueTimezone = this.setTimezone(comparing, this.getTimezone(value));
|
|
308
|
-
return value.hasSame(comparingInValueTimezone, 'hour');
|
|
309
|
-
};
|
|
310
|
-
this.isAfter = (value, comparing) => {
|
|
311
|
-
return value > comparing;
|
|
312
|
-
};
|
|
313
|
-
this.isAfterYear = (value, comparing) => {
|
|
314
|
-
const comparingInValueTimezone = this.setTimezone(comparing, this.getTimezone(value));
|
|
315
|
-
const diff = value.diff(this.endOfYear(comparingInValueTimezone), 'years').toObject();
|
|
316
|
-
return diff.years > 0;
|
|
317
|
-
};
|
|
318
|
-
this.isAfterDay = (value, comparing) => {
|
|
319
|
-
const comparingInValueTimezone = this.setTimezone(comparing, this.getTimezone(value));
|
|
320
|
-
const diff = value.diff(this.endOfDay(comparingInValueTimezone), 'days').toObject();
|
|
321
|
-
return diff.days > 0;
|
|
322
|
-
};
|
|
323
|
-
this.isBefore = (value, comparing) => {
|
|
324
|
-
return value < comparing;
|
|
325
|
-
};
|
|
326
|
-
this.isBeforeYear = (value, comparing) => {
|
|
327
|
-
const comparingInValueTimezone = this.setTimezone(comparing, this.getTimezone(value));
|
|
328
|
-
const diff = value.diff(this.startOfYear(comparingInValueTimezone), 'years').toObject();
|
|
329
|
-
return diff.years < 0;
|
|
330
|
-
};
|
|
331
|
-
this.isBeforeDay = (value, comparing) => {
|
|
332
|
-
const comparingInValueTimezone = this.setTimezone(comparing, this.getTimezone(value));
|
|
333
|
-
const diff = value.diff(this.startOfDay(comparingInValueTimezone), 'days').toObject();
|
|
334
|
-
return diff.days < 0;
|
|
335
|
-
};
|
|
336
|
-
this.isWithinRange = (value, [start, end]) => {
|
|
337
|
-
return this.isEqual(value, start) || this.isEqual(value, end) || this.isAfter(value, start) && this.isBefore(value, end);
|
|
338
|
-
};
|
|
339
|
-
this.startOfYear = value => {
|
|
340
|
-
return value.startOf('year');
|
|
341
|
-
};
|
|
342
|
-
this.startOfMonth = value => {
|
|
343
|
-
return value.startOf('month');
|
|
344
|
-
};
|
|
345
|
-
this.startOfWeek = value => {
|
|
346
|
-
return this.setLocaleToValue(value).startOf('week', {
|
|
347
|
-
useLocaleWeeks: true
|
|
348
|
-
});
|
|
349
|
-
};
|
|
350
|
-
this.startOfDay = value => {
|
|
351
|
-
return value.startOf('day');
|
|
352
|
-
};
|
|
353
|
-
this.endOfYear = value => {
|
|
354
|
-
return value.endOf('year');
|
|
355
|
-
};
|
|
356
|
-
this.endOfMonth = value => {
|
|
357
|
-
return value.endOf('month');
|
|
358
|
-
};
|
|
359
|
-
this.endOfWeek = value => {
|
|
360
|
-
return this.setLocaleToValue(value).endOf('week', {
|
|
361
|
-
useLocaleWeeks: true
|
|
362
|
-
});
|
|
363
|
-
};
|
|
364
|
-
this.endOfDay = value => {
|
|
365
|
-
return value.endOf('day');
|
|
366
|
-
};
|
|
367
|
-
this.addYears = (value, amount) => {
|
|
368
|
-
return value.plus({
|
|
369
|
-
years: amount
|
|
370
|
-
});
|
|
371
|
-
};
|
|
372
|
-
this.addMonths = (value, amount) => {
|
|
373
|
-
return value.plus({
|
|
374
|
-
months: amount
|
|
375
|
-
});
|
|
376
|
-
};
|
|
377
|
-
this.addWeeks = (value, amount) => {
|
|
378
|
-
return value.plus({
|
|
379
|
-
weeks: amount
|
|
380
|
-
});
|
|
381
|
-
};
|
|
382
|
-
this.addDays = (value, amount) => {
|
|
383
|
-
return value.plus({
|
|
384
|
-
days: amount
|
|
385
|
-
});
|
|
386
|
-
};
|
|
387
|
-
this.addHours = (value, amount) => {
|
|
388
|
-
return value.plus({
|
|
389
|
-
hours: amount
|
|
390
|
-
});
|
|
391
|
-
};
|
|
392
|
-
this.addMinutes = (value, amount) => {
|
|
393
|
-
return value.plus({
|
|
394
|
-
minutes: amount
|
|
395
|
-
});
|
|
396
|
-
};
|
|
397
|
-
this.addSeconds = (value, amount) => {
|
|
398
|
-
return value.plus({
|
|
399
|
-
seconds: amount
|
|
400
|
-
});
|
|
401
|
-
};
|
|
402
|
-
this.getYear = value => {
|
|
403
|
-
return value.get('year');
|
|
404
|
-
};
|
|
405
|
-
this.getMonth = value => {
|
|
406
|
-
// See https://github.com/moment/luxon/blob/master/docs/moment.md#major-functional-differences
|
|
407
|
-
return value.get('month') - 1;
|
|
408
|
-
};
|
|
409
|
-
this.getDate = value => {
|
|
410
|
-
return value.get('day');
|
|
411
|
-
};
|
|
412
|
-
this.getHours = value => {
|
|
413
|
-
return value.get('hour');
|
|
414
|
-
};
|
|
415
|
-
this.getMinutes = value => {
|
|
416
|
-
return value.get('minute');
|
|
417
|
-
};
|
|
418
|
-
this.getSeconds = value => {
|
|
419
|
-
return value.get('second');
|
|
420
|
-
};
|
|
421
|
-
this.getMilliseconds = value => {
|
|
422
|
-
return value.get('millisecond');
|
|
423
|
-
};
|
|
424
|
-
this.setYear = (value, year) => {
|
|
425
|
-
return value.set({
|
|
426
|
-
year
|
|
427
|
-
});
|
|
428
|
-
};
|
|
429
|
-
this.setMonth = (value, month) => {
|
|
430
|
-
return value.set({
|
|
431
|
-
month: month + 1
|
|
432
|
-
});
|
|
433
|
-
};
|
|
434
|
-
this.setDate = (value, date) => {
|
|
435
|
-
return value.set({
|
|
436
|
-
day: date
|
|
437
|
-
});
|
|
438
|
-
};
|
|
439
|
-
this.setHours = (value, hours) => {
|
|
440
|
-
return value.set({
|
|
441
|
-
hour: hours
|
|
442
|
-
});
|
|
443
|
-
};
|
|
444
|
-
this.setMinutes = (value, minutes) => {
|
|
445
|
-
return value.set({
|
|
446
|
-
minute: minutes
|
|
447
|
-
});
|
|
448
|
-
};
|
|
449
|
-
this.setSeconds = (value, seconds) => {
|
|
450
|
-
return value.set({
|
|
451
|
-
second: seconds
|
|
452
|
-
});
|
|
453
|
-
};
|
|
454
|
-
this.setMilliseconds = (value, milliseconds) => {
|
|
455
|
-
return value.set({
|
|
456
|
-
millisecond: milliseconds
|
|
256
|
+
const expandedToken = DateTime.expandFormat(token, {
|
|
257
|
+
locale: this.locale
|
|
457
258
|
});
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
const firstDay = this.startOfWeek(this.startOfMonth(value));
|
|
464
|
-
const lastDay = this.endOfWeek(this.endOfMonth(value));
|
|
465
|
-
const {
|
|
466
|
-
days
|
|
467
|
-
} = lastDay.diff(firstDay, 'days').toObject();
|
|
468
|
-
const weeks = [];
|
|
469
|
-
new Array(Math.round(days)).fill(0).map((_, i) => i).map(day => firstDay.plus({
|
|
470
|
-
days: day
|
|
471
|
-
})).forEach((v, i) => {
|
|
472
|
-
if (i === 0 || i % 7 === 0 && i > 6) {
|
|
473
|
-
weeks.push([v]);
|
|
474
|
-
return;
|
|
259
|
+
return expandedToken.replace(catchWordsRegexp, (substring, g1, g2) => {
|
|
260
|
+
const word = g1 || g2; // words are either in group 1 or group 2
|
|
261
|
+
|
|
262
|
+
if (isWordComposedOfTokens.test(word)) {
|
|
263
|
+
return substring;
|
|
475
264
|
}
|
|
476
|
-
|
|
265
|
+
return `'${substring}'`;
|
|
477
266
|
});
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
267
|
+
}).join('')
|
|
268
|
+
// The returned format can contain `yyyyy` which means year between 4 and 6 digits.
|
|
269
|
+
// This value is supported by luxon parser but not luxon formatter.
|
|
270
|
+
// To avoid conflicts, we replace it by 4 digits which is enough for most use-cases.
|
|
271
|
+
.replace('yyyyy', 'yyyy');
|
|
272
|
+
};
|
|
273
|
+
isValid = value => {
|
|
274
|
+
if (value === null) {
|
|
275
|
+
return false;
|
|
276
|
+
}
|
|
277
|
+
return value.isValid;
|
|
278
|
+
};
|
|
279
|
+
format = (value, formatKey) => {
|
|
280
|
+
return this.formatByString(value, this.formats[formatKey]);
|
|
281
|
+
};
|
|
282
|
+
formatByString = (value, format) => {
|
|
283
|
+
return value.setLocale(this.locale).toFormat(format);
|
|
284
|
+
};
|
|
285
|
+
formatNumber = numberToFormat => {
|
|
286
|
+
return numberToFormat;
|
|
287
|
+
};
|
|
288
|
+
isEqual = (value, comparing) => {
|
|
289
|
+
if (value === null && comparing === null) {
|
|
290
|
+
return true;
|
|
291
|
+
}
|
|
292
|
+
if (value === null || comparing === null) {
|
|
293
|
+
return false;
|
|
294
|
+
}
|
|
295
|
+
return +value === +comparing;
|
|
296
|
+
};
|
|
297
|
+
isSameYear = (value, comparing) => {
|
|
298
|
+
const comparingInValueTimezone = this.setTimezone(comparing, this.getTimezone(value));
|
|
299
|
+
return value.hasSame(comparingInValueTimezone, 'year');
|
|
300
|
+
};
|
|
301
|
+
isSameMonth = (value, comparing) => {
|
|
302
|
+
const comparingInValueTimezone = this.setTimezone(comparing, this.getTimezone(value));
|
|
303
|
+
return value.hasSame(comparingInValueTimezone, 'month');
|
|
304
|
+
};
|
|
305
|
+
isSameDay = (value, comparing) => {
|
|
306
|
+
const comparingInValueTimezone = this.setTimezone(comparing, this.getTimezone(value));
|
|
307
|
+
return value.hasSame(comparingInValueTimezone, 'day');
|
|
308
|
+
};
|
|
309
|
+
isSameHour = (value, comparing) => {
|
|
310
|
+
const comparingInValueTimezone = this.setTimezone(comparing, this.getTimezone(value));
|
|
311
|
+
return value.hasSame(comparingInValueTimezone, 'hour');
|
|
312
|
+
};
|
|
313
|
+
isAfter = (value, comparing) => {
|
|
314
|
+
return value > comparing;
|
|
315
|
+
};
|
|
316
|
+
isAfterYear = (value, comparing) => {
|
|
317
|
+
const comparingInValueTimezone = this.setTimezone(comparing, this.getTimezone(value));
|
|
318
|
+
const diff = value.diff(this.endOfYear(comparingInValueTimezone), 'years').toObject();
|
|
319
|
+
return diff.years > 0;
|
|
320
|
+
};
|
|
321
|
+
isAfterDay = (value, comparing) => {
|
|
322
|
+
const comparingInValueTimezone = this.setTimezone(comparing, this.getTimezone(value));
|
|
323
|
+
const diff = value.diff(this.endOfDay(comparingInValueTimezone), 'days').toObject();
|
|
324
|
+
return diff.days > 0;
|
|
325
|
+
};
|
|
326
|
+
isBefore = (value, comparing) => {
|
|
327
|
+
return value < comparing;
|
|
328
|
+
};
|
|
329
|
+
isBeforeYear = (value, comparing) => {
|
|
330
|
+
const comparingInValueTimezone = this.setTimezone(comparing, this.getTimezone(value));
|
|
331
|
+
const diff = value.diff(this.startOfYear(comparingInValueTimezone), 'years').toObject();
|
|
332
|
+
return diff.years < 0;
|
|
333
|
+
};
|
|
334
|
+
isBeforeDay = (value, comparing) => {
|
|
335
|
+
const comparingInValueTimezone = this.setTimezone(comparing, this.getTimezone(value));
|
|
336
|
+
const diff = value.diff(this.startOfDay(comparingInValueTimezone), 'days').toObject();
|
|
337
|
+
return diff.days < 0;
|
|
338
|
+
};
|
|
339
|
+
isWithinRange = (value, [start, end]) => {
|
|
340
|
+
return this.isEqual(value, start) || this.isEqual(value, end) || this.isAfter(value, start) && this.isBefore(value, end);
|
|
341
|
+
};
|
|
342
|
+
startOfYear = value => {
|
|
343
|
+
return value.startOf('year');
|
|
344
|
+
};
|
|
345
|
+
startOfMonth = value => {
|
|
346
|
+
return value.startOf('month');
|
|
347
|
+
};
|
|
348
|
+
startOfWeek = value => {
|
|
349
|
+
return this.setLocaleToValue(value).startOf('week', {
|
|
350
|
+
useLocaleWeeks: true
|
|
351
|
+
});
|
|
352
|
+
};
|
|
353
|
+
startOfDay = value => {
|
|
354
|
+
return value.startOf('day');
|
|
355
|
+
};
|
|
356
|
+
endOfYear = value => {
|
|
357
|
+
return value.endOf('year');
|
|
358
|
+
};
|
|
359
|
+
endOfMonth = value => {
|
|
360
|
+
return value.endOf('month');
|
|
361
|
+
};
|
|
362
|
+
endOfWeek = value => {
|
|
363
|
+
return this.setLocaleToValue(value).endOf('week', {
|
|
364
|
+
useLocaleWeeks: true
|
|
365
|
+
});
|
|
366
|
+
};
|
|
367
|
+
endOfDay = value => {
|
|
368
|
+
return value.endOf('day');
|
|
369
|
+
};
|
|
370
|
+
addYears = (value, amount) => {
|
|
371
|
+
return value.plus({
|
|
372
|
+
years: amount
|
|
373
|
+
});
|
|
374
|
+
};
|
|
375
|
+
addMonths = (value, amount) => {
|
|
376
|
+
return value.plus({
|
|
377
|
+
months: amount
|
|
378
|
+
});
|
|
379
|
+
};
|
|
380
|
+
addWeeks = (value, amount) => {
|
|
381
|
+
return value.plus({
|
|
382
|
+
weeks: amount
|
|
383
|
+
});
|
|
384
|
+
};
|
|
385
|
+
addDays = (value, amount) => {
|
|
386
|
+
return value.plus({
|
|
387
|
+
days: amount
|
|
388
|
+
});
|
|
389
|
+
};
|
|
390
|
+
addHours = (value, amount) => {
|
|
391
|
+
return value.plus({
|
|
392
|
+
hours: amount
|
|
393
|
+
});
|
|
394
|
+
};
|
|
395
|
+
addMinutes = (value, amount) => {
|
|
396
|
+
return value.plus({
|
|
397
|
+
minutes: amount
|
|
398
|
+
});
|
|
399
|
+
};
|
|
400
|
+
addSeconds = (value, amount) => {
|
|
401
|
+
return value.plus({
|
|
402
|
+
seconds: amount
|
|
403
|
+
});
|
|
404
|
+
};
|
|
405
|
+
getYear = value => {
|
|
406
|
+
return value.get('year');
|
|
407
|
+
};
|
|
408
|
+
getMonth = value => {
|
|
409
|
+
// See https://github.com/moment/luxon/blob/master/docs/moment.md#major-functional-differences
|
|
410
|
+
return value.get('month') - 1;
|
|
411
|
+
};
|
|
412
|
+
getDate = value => {
|
|
413
|
+
return value.get('day');
|
|
414
|
+
};
|
|
415
|
+
getHours = value => {
|
|
416
|
+
return value.get('hour');
|
|
417
|
+
};
|
|
418
|
+
getMinutes = value => {
|
|
419
|
+
return value.get('minute');
|
|
420
|
+
};
|
|
421
|
+
getSeconds = value => {
|
|
422
|
+
return value.get('second');
|
|
423
|
+
};
|
|
424
|
+
getMilliseconds = value => {
|
|
425
|
+
return value.get('millisecond');
|
|
426
|
+
};
|
|
427
|
+
setYear = (value, year) => {
|
|
428
|
+
return value.set({
|
|
429
|
+
year
|
|
430
|
+
});
|
|
431
|
+
};
|
|
432
|
+
setMonth = (value, month) => {
|
|
433
|
+
return value.set({
|
|
434
|
+
month: month + 1
|
|
435
|
+
});
|
|
436
|
+
};
|
|
437
|
+
setDate = (value, date) => {
|
|
438
|
+
return value.set({
|
|
439
|
+
day: date
|
|
440
|
+
});
|
|
441
|
+
};
|
|
442
|
+
setHours = (value, hours) => {
|
|
443
|
+
return value.set({
|
|
444
|
+
hour: hours
|
|
445
|
+
});
|
|
446
|
+
};
|
|
447
|
+
setMinutes = (value, minutes) => {
|
|
448
|
+
return value.set({
|
|
449
|
+
minute: minutes
|
|
450
|
+
});
|
|
451
|
+
};
|
|
452
|
+
setSeconds = (value, seconds) => {
|
|
453
|
+
return value.set({
|
|
454
|
+
second: seconds
|
|
455
|
+
});
|
|
456
|
+
};
|
|
457
|
+
setMilliseconds = (value, milliseconds) => {
|
|
458
|
+
return value.set({
|
|
459
|
+
millisecond: milliseconds
|
|
460
|
+
});
|
|
461
|
+
};
|
|
462
|
+
getDaysInMonth = value => {
|
|
463
|
+
return value.daysInMonth;
|
|
464
|
+
};
|
|
465
|
+
getWeekArray = value => {
|
|
466
|
+
const firstDay = this.startOfWeek(this.startOfMonth(value));
|
|
467
|
+
const lastDay = this.endOfWeek(this.endOfMonth(value));
|
|
468
|
+
const {
|
|
469
|
+
days
|
|
470
|
+
} = lastDay.diff(firstDay, 'days').toObject();
|
|
471
|
+
const weeks = [];
|
|
472
|
+
new Array(Math.round(days)).fill(0).map((_, i) => i).map(day => firstDay.plus({
|
|
473
|
+
days: day
|
|
474
|
+
})).forEach((v, i) => {
|
|
475
|
+
if (i === 0 || i % 7 === 0 && i > 6) {
|
|
476
|
+
weeks.push([v]);
|
|
477
|
+
return;
|
|
495
478
|
}
|
|
496
|
-
|
|
497
|
-
};
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
479
|
+
weeks[weeks.length - 1].push(v);
|
|
480
|
+
});
|
|
481
|
+
return weeks;
|
|
482
|
+
};
|
|
483
|
+
getWeekNumber = value => {
|
|
484
|
+
/* v8 ignore next */
|
|
485
|
+
return value.localWeekNumber ?? value.weekNumber;
|
|
486
|
+
};
|
|
487
|
+
getDayOfWeek = value => {
|
|
488
|
+
return value.weekday;
|
|
489
|
+
};
|
|
490
|
+
getYearRange = ([start, end]) => {
|
|
491
|
+
const startDate = this.startOfYear(start);
|
|
492
|
+
const endDate = this.endOfYear(end);
|
|
493
|
+
const years = [];
|
|
494
|
+
let current = startDate;
|
|
495
|
+
while (this.isBefore(current, endDate)) {
|
|
496
|
+
years.push(current);
|
|
497
|
+
current = this.addYears(current, 1);
|
|
498
|
+
}
|
|
499
|
+
return years;
|
|
500
|
+
};
|
|
501
501
|
}
|