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