@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 defaultMoment from 'moment';
|
|
4
3
|
// From https://momentjs.com/docs/#/displaying/format/
|
|
5
4
|
const formatTokenMap = {
|
|
@@ -147,317 +146,314 @@ const MISSING_TIMEZONE_PLUGIN = ['Missing timezone plugin', 'To be able to use t
|
|
|
147
146
|
* SOFTWARE.
|
|
148
147
|
*/
|
|
149
148
|
export class AdapterMoment {
|
|
149
|
+
isMUIAdapter = true;
|
|
150
|
+
isTimezoneCompatible = true;
|
|
151
|
+
lib = 'moment';
|
|
152
|
+
escapedCharacters = {
|
|
153
|
+
start: '[',
|
|
154
|
+
end: ']'
|
|
155
|
+
};
|
|
156
|
+
formatTokenMap = (() => formatTokenMap)();
|
|
150
157
|
constructor({
|
|
151
158
|
locale,
|
|
152
159
|
formats,
|
|
153
160
|
instance
|
|
154
161
|
} = {}) {
|
|
155
|
-
this.
|
|
156
|
-
this.
|
|
157
|
-
this.
|
|
158
|
-
|
|
159
|
-
|
|
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
|
-
|
|
162
|
+
this.moment = instance || defaultMoment;
|
|
163
|
+
this.locale = locale;
|
|
164
|
+
this.formats = _extends({}, defaultFormats, formats);
|
|
165
|
+
}
|
|
166
|
+
setLocaleToValue = value => {
|
|
167
|
+
const expectedLocale = this.getCurrentLocaleCode();
|
|
168
|
+
if (expectedLocale === value.locale()) {
|
|
169
|
+
return value;
|
|
170
|
+
}
|
|
171
|
+
return value.locale(expectedLocale);
|
|
172
|
+
};
|
|
173
|
+
hasTimezonePlugin = () => typeof this.moment.tz !== 'undefined';
|
|
174
|
+
createSystemDate = value => {
|
|
175
|
+
const parsedValue = this.moment(value).local();
|
|
176
|
+
if (this.locale === undefined) {
|
|
177
|
+
return parsedValue;
|
|
178
|
+
}
|
|
179
|
+
return parsedValue.locale(this.locale);
|
|
180
|
+
};
|
|
181
|
+
createUTCDate = value => {
|
|
182
|
+
const parsedValue = this.moment.utc(value);
|
|
183
|
+
if (this.locale === undefined) {
|
|
184
|
+
return parsedValue;
|
|
185
|
+
}
|
|
186
|
+
return parsedValue.locale(this.locale);
|
|
187
|
+
};
|
|
188
|
+
createTZDate = (value, timezone) => {
|
|
189
|
+
/* v8 ignore next 3 */
|
|
190
|
+
if (!this.hasTimezonePlugin()) {
|
|
191
|
+
throw new Error(MISSING_TIMEZONE_PLUGIN);
|
|
192
|
+
}
|
|
193
|
+
const parsedValue = timezone === 'default' ? this.moment(value) : this.moment.tz(value, timezone);
|
|
194
|
+
if (this.locale === undefined) {
|
|
195
|
+
return parsedValue;
|
|
196
|
+
}
|
|
197
|
+
return parsedValue.locale(this.locale);
|
|
198
|
+
};
|
|
199
|
+
date = (value, timezone = 'default') => {
|
|
200
|
+
if (value === null) {
|
|
201
|
+
return null;
|
|
202
|
+
}
|
|
203
|
+
if (timezone === 'UTC') {
|
|
204
|
+
return this.createUTCDate(value);
|
|
205
|
+
}
|
|
206
|
+
if (timezone === 'system' || timezone === 'default' && !this.hasTimezonePlugin()) {
|
|
207
|
+
return this.createSystemDate(value);
|
|
208
|
+
}
|
|
209
|
+
return this.createTZDate(value, timezone);
|
|
210
|
+
};
|
|
211
|
+
getInvalidDate = () => this.moment(new Date('Invalid Date'));
|
|
212
|
+
getTimezone = value => {
|
|
213
|
+
// @ts-ignore
|
|
214
|
+
// eslint-disable-next-line no-underscore-dangle
|
|
215
|
+
const zone = value._z?.name;
|
|
216
|
+
const defaultZone = value.isUTC() ? 'UTC' : 'system';
|
|
217
|
+
|
|
218
|
+
// @ts-ignore
|
|
219
|
+
return zone ?? this.moment.defaultZone?.name ?? defaultZone;
|
|
220
|
+
};
|
|
221
|
+
setTimezone = (value, timezone) => {
|
|
222
|
+
if (this.getTimezone(value) === timezone) {
|
|
223
|
+
return value;
|
|
224
|
+
}
|
|
225
|
+
if (timezone === 'UTC') {
|
|
226
|
+
return value.clone().utc();
|
|
227
|
+
}
|
|
228
|
+
if (timezone === 'system') {
|
|
229
|
+
return value.clone().local();
|
|
230
|
+
}
|
|
231
|
+
if (!this.hasTimezonePlugin()) {
|
|
189
232
|
/* v8 ignore next 3 */
|
|
190
|
-
if (
|
|
233
|
+
if (timezone !== 'default') {
|
|
191
234
|
throw new Error(MISSING_TIMEZONE_PLUGIN);
|
|
192
235
|
}
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
this.
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
this.
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
if (
|
|
229
|
-
return
|
|
230
|
-
}
|
|
231
|
-
if (!this.hasTimezonePlugin()) {
|
|
232
|
-
/* v8 ignore next 3 */
|
|
233
|
-
if (timezone !== 'default') {
|
|
234
|
-
throw new Error(MISSING_TIMEZONE_PLUGIN);
|
|
235
|
-
}
|
|
236
|
-
return value;
|
|
237
|
-
}
|
|
238
|
-
const cleanZone = timezone === 'default' ?
|
|
239
|
-
// @ts-ignore
|
|
240
|
-
this.moment.defaultZone?.name ?? 'system' : timezone;
|
|
241
|
-
if (cleanZone === 'system') {
|
|
242
|
-
return value.clone().local();
|
|
243
|
-
}
|
|
244
|
-
const newValue = value.clone();
|
|
245
|
-
newValue.tz(cleanZone);
|
|
246
|
-
return newValue;
|
|
247
|
-
};
|
|
248
|
-
this.toJsDate = value => {
|
|
249
|
-
return value.toDate();
|
|
250
|
-
};
|
|
251
|
-
this.parse = (value, format) => {
|
|
252
|
-
if (value === '') {
|
|
253
|
-
return null;
|
|
254
|
-
}
|
|
255
|
-
if (this.locale) {
|
|
256
|
-
return this.moment(value, format, this.locale, true);
|
|
257
|
-
}
|
|
258
|
-
return this.moment(value, format, true);
|
|
259
|
-
};
|
|
260
|
-
this.getCurrentLocaleCode = () => {
|
|
261
|
-
return this.locale || defaultMoment.locale();
|
|
262
|
-
};
|
|
263
|
-
this.is12HourCycleInCurrentLocale = () => {
|
|
264
|
-
return /A|a/.test(defaultMoment.localeData(this.getCurrentLocaleCode()).longDateFormat('LT'));
|
|
265
|
-
};
|
|
266
|
-
this.expandFormat = format => {
|
|
267
|
-
// @see https://github.com/moment/moment/blob/develop/src/lib/format/format.js#L6
|
|
268
|
-
const localFormattingTokens = /(\[[^[]*\])|(\\)?(LTS|LT|LL?L?L?|l{1,4})|./g;
|
|
269
|
-
return format.match(localFormattingTokens).map(token => {
|
|
270
|
-
const firstCharacter = token[0];
|
|
271
|
-
if (firstCharacter === 'L' || firstCharacter === ';') {
|
|
272
|
-
return defaultMoment.localeData(this.getCurrentLocaleCode()).longDateFormat(token);
|
|
273
|
-
}
|
|
274
|
-
return token;
|
|
275
|
-
}).join('');
|
|
276
|
-
};
|
|
277
|
-
this.isValid = value => {
|
|
278
|
-
if (value == null) {
|
|
279
|
-
return false;
|
|
280
|
-
}
|
|
281
|
-
return value.isValid();
|
|
282
|
-
};
|
|
283
|
-
this.format = (value, formatKey) => {
|
|
284
|
-
return this.formatByString(value, this.formats[formatKey]);
|
|
285
|
-
};
|
|
286
|
-
this.formatByString = (value, formatString) => {
|
|
287
|
-
const clonedDate = value.clone();
|
|
288
|
-
clonedDate.locale(this.getCurrentLocaleCode());
|
|
289
|
-
return clonedDate.format(formatString);
|
|
290
|
-
};
|
|
291
|
-
this.formatNumber = numberToFormat => {
|
|
292
|
-
return numberToFormat;
|
|
293
|
-
};
|
|
294
|
-
this.isEqual = (value, comparing) => {
|
|
295
|
-
if (value === null && comparing === null) {
|
|
296
|
-
return true;
|
|
297
|
-
}
|
|
298
|
-
if (value === null || comparing === null) {
|
|
299
|
-
return false;
|
|
236
|
+
return value;
|
|
237
|
+
}
|
|
238
|
+
const cleanZone = timezone === 'default' ?
|
|
239
|
+
// @ts-ignore
|
|
240
|
+
this.moment.defaultZone?.name ?? 'system' : timezone;
|
|
241
|
+
if (cleanZone === 'system') {
|
|
242
|
+
return value.clone().local();
|
|
243
|
+
}
|
|
244
|
+
const newValue = value.clone();
|
|
245
|
+
newValue.tz(cleanZone);
|
|
246
|
+
return newValue;
|
|
247
|
+
};
|
|
248
|
+
toJsDate = value => {
|
|
249
|
+
return value.toDate();
|
|
250
|
+
};
|
|
251
|
+
parse = (value, format) => {
|
|
252
|
+
if (value === '') {
|
|
253
|
+
return null;
|
|
254
|
+
}
|
|
255
|
+
if (this.locale) {
|
|
256
|
+
return this.moment(value, format, this.locale, true);
|
|
257
|
+
}
|
|
258
|
+
return this.moment(value, format, true);
|
|
259
|
+
};
|
|
260
|
+
getCurrentLocaleCode = () => {
|
|
261
|
+
return this.locale || defaultMoment.locale();
|
|
262
|
+
};
|
|
263
|
+
is12HourCycleInCurrentLocale = () => {
|
|
264
|
+
return /A|a/.test(defaultMoment.localeData(this.getCurrentLocaleCode()).longDateFormat('LT'));
|
|
265
|
+
};
|
|
266
|
+
expandFormat = format => {
|
|
267
|
+
// @see https://github.com/moment/moment/blob/develop/src/lib/format/format.js#L6
|
|
268
|
+
const localFormattingTokens = /(\[[^[]*\])|(\\)?(LTS|LT|LL?L?L?|l{1,4})|./g;
|
|
269
|
+
return format.match(localFormattingTokens).map(token => {
|
|
270
|
+
const firstCharacter = token[0];
|
|
271
|
+
if (firstCharacter === 'L' || firstCharacter === ';') {
|
|
272
|
+
return defaultMoment.localeData(this.getCurrentLocaleCode()).longDateFormat(token);
|
|
300
273
|
}
|
|
301
|
-
return
|
|
302
|
-
};
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
this.
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
274
|
+
return token;
|
|
275
|
+
}).join('');
|
|
276
|
+
};
|
|
277
|
+
isValid = value => {
|
|
278
|
+
if (value == null) {
|
|
279
|
+
return false;
|
|
280
|
+
}
|
|
281
|
+
return value.isValid();
|
|
282
|
+
};
|
|
283
|
+
format = (value, formatKey) => {
|
|
284
|
+
return this.formatByString(value, this.formats[formatKey]);
|
|
285
|
+
};
|
|
286
|
+
formatByString = (value, formatString) => {
|
|
287
|
+
const clonedDate = value.clone();
|
|
288
|
+
clonedDate.locale(this.getCurrentLocaleCode());
|
|
289
|
+
return clonedDate.format(formatString);
|
|
290
|
+
};
|
|
291
|
+
formatNumber = numberToFormat => {
|
|
292
|
+
return numberToFormat;
|
|
293
|
+
};
|
|
294
|
+
isEqual = (value, comparing) => {
|
|
295
|
+
if (value === null && comparing === null) {
|
|
296
|
+
return true;
|
|
297
|
+
}
|
|
298
|
+
if (value === null || comparing === null) {
|
|
299
|
+
return false;
|
|
300
|
+
}
|
|
301
|
+
return value.isSame(comparing);
|
|
302
|
+
};
|
|
303
|
+
isSameYear = (value, comparing) => {
|
|
304
|
+
return value.isSame(comparing, 'year');
|
|
305
|
+
};
|
|
306
|
+
isSameMonth = (value, comparing) => {
|
|
307
|
+
return value.isSame(comparing, 'month');
|
|
308
|
+
};
|
|
309
|
+
isSameDay = (value, comparing) => {
|
|
310
|
+
return value.isSame(comparing, 'day');
|
|
311
|
+
};
|
|
312
|
+
isSameHour = (value, comparing) => {
|
|
313
|
+
return value.isSame(comparing, 'hour');
|
|
314
|
+
};
|
|
315
|
+
isAfter = (value, comparing) => {
|
|
316
|
+
return value.isAfter(comparing);
|
|
317
|
+
};
|
|
318
|
+
isAfterYear = (value, comparing) => {
|
|
319
|
+
return value.isAfter(comparing, 'year');
|
|
320
|
+
};
|
|
321
|
+
isAfterDay = (value, comparing) => {
|
|
322
|
+
return value.isAfter(comparing, 'day');
|
|
323
|
+
};
|
|
324
|
+
isBefore = (value, comparing) => {
|
|
325
|
+
return value.isBefore(comparing);
|
|
326
|
+
};
|
|
327
|
+
isBeforeYear = (value, comparing) => {
|
|
328
|
+
return value.isBefore(comparing, 'year');
|
|
329
|
+
};
|
|
330
|
+
isBeforeDay = (value, comparing) => {
|
|
331
|
+
return value.isBefore(comparing, 'day');
|
|
332
|
+
};
|
|
333
|
+
isWithinRange = (value, [start, end]) => {
|
|
334
|
+
return value.isBetween(start, end, null, '[]');
|
|
335
|
+
};
|
|
336
|
+
startOfYear = value => {
|
|
337
|
+
return value.clone().startOf('year');
|
|
338
|
+
};
|
|
339
|
+
startOfMonth = value => {
|
|
340
|
+
return value.clone().startOf('month');
|
|
341
|
+
};
|
|
342
|
+
startOfWeek = value => {
|
|
343
|
+
return this.setLocaleToValue(value.clone()).startOf('week');
|
|
344
|
+
};
|
|
345
|
+
startOfDay = value => {
|
|
346
|
+
return value.clone().startOf('day');
|
|
347
|
+
};
|
|
348
|
+
endOfYear = value => {
|
|
349
|
+
return value.clone().endOf('year');
|
|
350
|
+
};
|
|
351
|
+
endOfMonth = value => {
|
|
352
|
+
return value.clone().endOf('month');
|
|
353
|
+
};
|
|
354
|
+
endOfWeek = value => {
|
|
355
|
+
return this.setLocaleToValue(value.clone()).endOf('week');
|
|
356
|
+
};
|
|
357
|
+
endOfDay = value => {
|
|
358
|
+
return value.clone().endOf('day');
|
|
359
|
+
};
|
|
360
|
+
addYears = (value, amount) => {
|
|
361
|
+
return amount < 0 ? value.clone().subtract(Math.abs(amount), 'years') : value.clone().add(amount, 'years');
|
|
362
|
+
};
|
|
363
|
+
addMonths = (value, amount) => {
|
|
364
|
+
return amount < 0 ? value.clone().subtract(Math.abs(amount), 'months') : value.clone().add(amount, 'months');
|
|
365
|
+
};
|
|
366
|
+
addWeeks = (value, amount) => {
|
|
367
|
+
return amount < 0 ? value.clone().subtract(Math.abs(amount), 'weeks') : value.clone().add(amount, 'weeks');
|
|
368
|
+
};
|
|
369
|
+
addDays = (value, amount) => {
|
|
370
|
+
return amount < 0 ? value.clone().subtract(Math.abs(amount), 'days') : value.clone().add(amount, 'days');
|
|
371
|
+
};
|
|
372
|
+
addHours = (value, amount) => {
|
|
373
|
+
return amount < 0 ? value.clone().subtract(Math.abs(amount), 'hours') : value.clone().add(amount, 'hours');
|
|
374
|
+
};
|
|
375
|
+
addMinutes = (value, amount) => {
|
|
376
|
+
return amount < 0 ? value.clone().subtract(Math.abs(amount), 'minutes') : value.clone().add(amount, 'minutes');
|
|
377
|
+
};
|
|
378
|
+
addSeconds = (value, amount) => {
|
|
379
|
+
return amount < 0 ? value.clone().subtract(Math.abs(amount), 'seconds') : value.clone().add(amount, 'seconds');
|
|
380
|
+
};
|
|
381
|
+
getYear = value => {
|
|
382
|
+
return value.get('year');
|
|
383
|
+
};
|
|
384
|
+
getMonth = value => {
|
|
385
|
+
return value.get('month');
|
|
386
|
+
};
|
|
387
|
+
getDate = value => {
|
|
388
|
+
return value.get('date');
|
|
389
|
+
};
|
|
390
|
+
getHours = value => {
|
|
391
|
+
return value.get('hours');
|
|
392
|
+
};
|
|
393
|
+
getMinutes = value => {
|
|
394
|
+
return value.get('minutes');
|
|
395
|
+
};
|
|
396
|
+
getSeconds = value => {
|
|
397
|
+
return value.get('seconds');
|
|
398
|
+
};
|
|
399
|
+
getMilliseconds = value => {
|
|
400
|
+
return value.get('milliseconds');
|
|
401
|
+
};
|
|
402
|
+
setYear = (value, year) => {
|
|
403
|
+
return value.clone().year(year);
|
|
404
|
+
};
|
|
405
|
+
setMonth = (value, month) => {
|
|
406
|
+
return value.clone().month(month);
|
|
407
|
+
};
|
|
408
|
+
setDate = (value, date) => {
|
|
409
|
+
return value.clone().date(date);
|
|
410
|
+
};
|
|
411
|
+
setHours = (value, hours) => {
|
|
412
|
+
return value.clone().hours(hours);
|
|
413
|
+
};
|
|
414
|
+
setMinutes = (value, minutes) => {
|
|
415
|
+
return value.clone().minutes(minutes);
|
|
416
|
+
};
|
|
417
|
+
setSeconds = (value, seconds) => {
|
|
418
|
+
return value.clone().seconds(seconds);
|
|
419
|
+
};
|
|
420
|
+
setMilliseconds = (value, milliseconds) => {
|
|
421
|
+
return value.clone().milliseconds(milliseconds);
|
|
422
|
+
};
|
|
423
|
+
getDaysInMonth = value => {
|
|
424
|
+
return value.daysInMonth();
|
|
425
|
+
};
|
|
426
|
+
getWeekArray = value => {
|
|
427
|
+
const start = this.startOfWeek(this.startOfMonth(value));
|
|
428
|
+
const end = this.endOfWeek(this.endOfMonth(value));
|
|
429
|
+
let count = 0;
|
|
430
|
+
let current = start;
|
|
431
|
+
let currentDayOfYear = current.get('dayOfYear');
|
|
432
|
+
const nestedWeeks = [];
|
|
433
|
+
while (current.isBefore(end)) {
|
|
434
|
+
const weekNumber = Math.floor(count / 7);
|
|
435
|
+
nestedWeeks[weekNumber] = nestedWeeks[weekNumber] || [];
|
|
436
|
+
nestedWeeks[weekNumber].push(current);
|
|
437
|
+
const prevDayOfYear = currentDayOfYear;
|
|
438
|
+
current = this.addDays(current, 1);
|
|
439
|
+
currentDayOfYear = current.get('dayOfYear');
|
|
440
440
|
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
}
|
|
447
|
-
count += 1;
|
|
441
|
+
// If there is a TZ change at midnight, adding 1 day may only increase the date by 23 hours to 11pm
|
|
442
|
+
// To fix, bump the date into the next day (add 12 hours) and then revert to the start of the day
|
|
443
|
+
// See https://github.com/moment/moment/issues/4743#issuecomment-811306874 for context.
|
|
444
|
+
if (prevDayOfYear === currentDayOfYear) {
|
|
445
|
+
current = current.add(12, 'h').startOf('day');
|
|
448
446
|
}
|
|
449
|
-
|
|
450
|
-
}
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
this.formats = _extends({}, defaultFormats, formats);
|
|
460
|
-
}
|
|
447
|
+
count += 1;
|
|
448
|
+
}
|
|
449
|
+
return nestedWeeks;
|
|
450
|
+
};
|
|
451
|
+
getWeekNumber = value => {
|
|
452
|
+
return value.week();
|
|
453
|
+
};
|
|
454
|
+
getDayOfWeek = value => {
|
|
455
|
+
return value.day() + 1;
|
|
456
|
+
};
|
|
461
457
|
getYearRange([start, end]) {
|
|
462
458
|
const startDate = this.startOfYear(start);
|
|
463
459
|
const endDate = this.endOfYear(end);
|