daterangepicker-4.x 4.3.0 → 4.3.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/README.md +2 -2
- package/daterangepicker.js +103 -118
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -18,8 +18,8 @@ Above samples are based on the [original repository](https://github.com/dangross
|
|
|
18
18
|
```html
|
|
19
19
|
<script type="text/javascript" src="https://cdn.jsdelivr.net/jquery/latest/jquery.min.js"></script>
|
|
20
20
|
<script type="text/javascript" src="https://cdn.jsdelivr.net/npm/luxon@3.5.0/build/global/luxon.min.js"></script>
|
|
21
|
-
<script type="text/javascript" src="https://cdn.jsdelivr.net/npm/daterangepicker-4.x@4.3.
|
|
22
|
-
<link type="text/css" href="https://cdn.jsdelivr.net/npm/daterangepicker-4.x@4.3.
|
|
21
|
+
<script type="text/javascript" src="https://cdn.jsdelivr.net/npm/daterangepicker-4.x@4.3.2/daterangepicker.min.js"></script>
|
|
22
|
+
<link type="text/css" href="https://cdn.jsdelivr.net/npm/daterangepicker-4.x@4.3.2/daterangepicker.min.css" rel="stylesheet" />
|
|
23
23
|
|
|
24
24
|
<input type="text" id="daterange" />
|
|
25
25
|
|
package/daterangepicker.js
CHANGED
|
@@ -207,6 +207,7 @@
|
|
|
207
207
|
this.buttonClasses = 'btn btn-sm';
|
|
208
208
|
this.applyButtonClasses = 'btn-primary';
|
|
209
209
|
this.cancelButtonClasses = 'btn-default';
|
|
210
|
+
this.warnings = true;
|
|
210
211
|
this.ranges = {};
|
|
211
212
|
|
|
212
213
|
this.locale = {
|
|
@@ -313,7 +314,7 @@
|
|
|
313
314
|
this.container.addClass(this.locale.direction);
|
|
314
315
|
|
|
315
316
|
for (let key of ['timePicker', 'singleDatePicker', 'timePicker24Hour', 'showWeekNumbers', 'showISOWeekNumbers',
|
|
316
|
-
'showDropdowns', 'linkedCalendars', 'showCustomRangeLabel', 'alwaysShowCalendars', 'autoApply', 'autoUpdateInput']) {
|
|
317
|
+
'showDropdowns', 'linkedCalendars', 'showCustomRangeLabel', 'alwaysShowCalendars', 'autoApply', 'autoUpdateInput', 'warnings']) {
|
|
317
318
|
if (typeof options[key] === 'boolean')
|
|
318
319
|
this[key] = options[key];
|
|
319
320
|
}
|
|
@@ -335,6 +336,29 @@
|
|
|
335
336
|
this[key] = function () { return false };
|
|
336
337
|
}
|
|
337
338
|
|
|
339
|
+
if (!this.singleDatePicker) {
|
|
340
|
+
for (let opt of ['minSpan', 'maxSpan']) {
|
|
341
|
+
if (['string', 'number', 'object'].includes(typeof options[opt])) {
|
|
342
|
+
if (options[opt] instanceof Duration && options[opt].isValid) {
|
|
343
|
+
this[opt] = options[opt];
|
|
344
|
+
} else if (Duration.fromISO(options[opt]).isValid) {
|
|
345
|
+
this[opt] = Duration.fromISO(options[opt]);
|
|
346
|
+
} else if (typeof options[opt] === 'number' && Duration.fromObject({ seconds: options[opt] }).isValid) {
|
|
347
|
+
this[opt] = Duration.fromObject({ seconds: options[opt] });
|
|
348
|
+
} else if (options[opt] === null) {
|
|
349
|
+
this[opt] = null;
|
|
350
|
+
} else {
|
|
351
|
+
console.error(`Option '${key}' is not valid`);
|
|
352
|
+
};
|
|
353
|
+
}
|
|
354
|
+
}
|
|
355
|
+
if (this.minSpan && this.maxSpan && this.minSpan > this.maxSpan) {
|
|
356
|
+
this.minSpan = null;
|
|
357
|
+
this.maxSpan = null;
|
|
358
|
+
console.warn(`Ignore option 'minSpan' and 'maxSpan', because 'minSpan' must be smaller than 'maxSpan'`);
|
|
359
|
+
}
|
|
360
|
+
}
|
|
361
|
+
|
|
338
362
|
if (typeof options.timePickerSeconds === 'boolean') // backward compatibility
|
|
339
363
|
this.timePickerStepSize = Duration.fromObject({ [options.timePickerSeconds ? 'seconds' : 'minutes']: 1 });
|
|
340
364
|
if (typeof options.timePickerIncrement === 'number') // backward compatibility
|
|
@@ -360,20 +384,13 @@
|
|
|
360
384
|
valid.push(...[8, 12].map(x => { return Duration.fromObject({ hours: x }) }));
|
|
361
385
|
|
|
362
386
|
if (valid.some(x => duration.rescale().equals(x))) {
|
|
363
|
-
|
|
364
|
-
console.error(`Option 'timePickerStepSize' ${JSON.stringify(duration.toObject())} must be smaller than 'maxSpan'`);
|
|
365
|
-
duration = this.timePickerStepSize;
|
|
366
|
-
} else if (this.minSpan && duration < this.minSpan) {
|
|
367
|
-
console.error(`Option 'timePickerStepSize' ${JSON.stringify(duration.toObject())} must be greater than 'minSpan'`);
|
|
368
|
-
duration = this.timePickerStepSize;
|
|
369
|
-
} else {
|
|
370
|
-
this.timePickerStepSize = duration.rescale();
|
|
371
|
-
}
|
|
387
|
+
this.timePickerStepSize = duration.rescale();
|
|
372
388
|
} else {
|
|
373
389
|
console.error(`Option 'timePickerStepSize' ${JSON.stringify(duration.toObject())} is not valid`);
|
|
374
|
-
duration = this.timePickerStepSize;
|
|
375
390
|
}
|
|
376
391
|
}
|
|
392
|
+
if (this.timePicker && this.maxSpan && this.timePickerStepSize > this.maxSpan)
|
|
393
|
+
console.error(`Option 'timePickerStepSize' ${JSON.stringify(this.timePickerStepSize.toObject())} must be smaller than 'maxSpan'`);
|
|
377
394
|
|
|
378
395
|
this.timePickerOpts = {
|
|
379
396
|
showMinutes: this.timePickerStepSize < Duration.fromObject({ hours: 1 }),
|
|
@@ -383,29 +400,6 @@
|
|
|
383
400
|
secondStep: this.timePickerStepSize.seconds
|
|
384
401
|
};
|
|
385
402
|
|
|
386
|
-
if (!this.singleDatePicker) {
|
|
387
|
-
for (let opt of ['minSpan', 'maxSpan']) {
|
|
388
|
-
if (['string', 'number', 'object'].includes(typeof options[opt])) {
|
|
389
|
-
if (options[opt] instanceof Duration && options[opt].isValid) {
|
|
390
|
-
this[opt] = options[opt];
|
|
391
|
-
} else if (Duration.fromISO(options[opt]).isValid) {
|
|
392
|
-
this[opt] = Duration.fromISO(options[opt]);
|
|
393
|
-
} else if (typeof options[opt] === 'number' && Duration.fromObject({ seconds: options[opt] }).isValid) {
|
|
394
|
-
this[opt] = Duration.fromObject({ seconds: options[opt] });
|
|
395
|
-
} else if (options[opt] === null) {
|
|
396
|
-
this[opt] = null;
|
|
397
|
-
} else {
|
|
398
|
-
console.error(`Option '${key}' is not valid`);
|
|
399
|
-
};
|
|
400
|
-
}
|
|
401
|
-
}
|
|
402
|
-
if (this.minSpan && this.maxSpan && this.minSpan > this.maxSpan) {
|
|
403
|
-
this.minSpan = null;
|
|
404
|
-
this.maxSpan = null;
|
|
405
|
-
console.warn(`Ignore option 'minSpan' and 'maxSpan', because 'minSpan' must be smaller than 'maxSpan'`);
|
|
406
|
-
}
|
|
407
|
-
}
|
|
408
|
-
|
|
409
403
|
for (let opt of ['startDate', 'endDate', 'minDate', 'maxDate', 'initalMonth']) {
|
|
410
404
|
if (opt == 'endDate' && this.singleDatePicker)
|
|
411
405
|
continue;
|
|
@@ -420,12 +414,14 @@
|
|
|
420
414
|
console.error(`Option '${opt}' must be a luxon.DateTime or Date or string`);
|
|
421
415
|
}
|
|
422
416
|
} else if (typeof options[opt] === 'string') {
|
|
417
|
+
const format = typeof this.locale.format === 'string' ? this.locale.format : DateTime.parseFormatForOpts(this.locale.format);
|
|
423
418
|
if (DateTime.fromISO(options[opt]).isValid) {
|
|
424
419
|
this[opt] = DateTime.fromISO(options[opt]);
|
|
425
|
-
} else if (
|
|
426
|
-
this[opt] = DateTime.fromFormat(options[opt],
|
|
420
|
+
} else if (DateTime.fromFormat(options[opt], format, { locale: DateTime.now().locale }).isValid) {
|
|
421
|
+
this[opt] = DateTime.fromFormat(options[opt], format, { locale: DateTime.now().locale });
|
|
427
422
|
} else {
|
|
428
|
-
|
|
423
|
+
const invalid = DateTime.fromFormat(options[opt], format, { locale: DateTime.now().locale }).invalidExplanation;
|
|
424
|
+
console.error(`Option '${opt}' is not a valid string: ${invalid}`);
|
|
429
425
|
}
|
|
430
426
|
}
|
|
431
427
|
}
|
|
@@ -456,7 +452,10 @@
|
|
|
456
452
|
this.setStartDate(start, false);
|
|
457
453
|
this.setEndDate(end, false);
|
|
458
454
|
} else {
|
|
459
|
-
|
|
455
|
+
if (this.singleDatePicker)
|
|
456
|
+
console.error(`Value in <input> is not a valid string: ${start.invalidExplanation}`)
|
|
457
|
+
else
|
|
458
|
+
console.error(`Value in <input> is not a valid string: ${start.invalidExplanation} - ${end.invalidExplanation}`);
|
|
460
459
|
}
|
|
461
460
|
}
|
|
462
461
|
}
|
|
@@ -466,7 +465,7 @@
|
|
|
466
465
|
this.endDate = this.startDate;
|
|
467
466
|
} else if (this.endDate < this.startDate) {
|
|
468
467
|
this.endDate = this.startDate;
|
|
469
|
-
console.warn(`Set endDate to ${this
|
|
468
|
+
console.warn(`Set 'endDate' to ${this - this.logDate(endDate)} because it was earlier than 'startDate'`);
|
|
470
469
|
}
|
|
471
470
|
|
|
472
471
|
if (!this.startDate && this.initalMonth) {
|
|
@@ -525,7 +524,7 @@
|
|
|
525
524
|
} else if (typeof options.ranges[range][0] === 'string' && DateTime.fromISO(options.ranges[range][0]).isValid) {
|
|
526
525
|
start = DateTime.fromISO(options.ranges[range][0]);
|
|
527
526
|
} else {
|
|
528
|
-
console.error(`Option 'ranges.${range}' is not a valid string or DateTime`);
|
|
527
|
+
console.error(`Option 'ranges.${range}' is not a valid ISO-8601 string or DateTime`);
|
|
529
528
|
}
|
|
530
529
|
}
|
|
531
530
|
if (['string', 'object'].includes(typeof options.ranges[range][1])) {
|
|
@@ -534,7 +533,7 @@
|
|
|
534
533
|
} else if (typeof options.ranges[range][1] === 'string' && DateTime.fromISO(options.ranges[range][1]).isValid) {
|
|
535
534
|
end = DateTime.fromISO(options.ranges[range][1]);
|
|
536
535
|
} else {
|
|
537
|
-
console.error(`Option 'ranges.${range}' is not a valid string or DateTime`);
|
|
536
|
+
console.error(`Option 'ranges.${range}' is not a valid ISO-8601 string or DateTime`);
|
|
538
537
|
}
|
|
539
538
|
}
|
|
540
539
|
if (start == null || end == null)
|
|
@@ -579,9 +578,8 @@
|
|
|
579
578
|
if (this.timePicker && this.autoApply)
|
|
580
579
|
this.autoApply = false;
|
|
581
580
|
|
|
582
|
-
if (this.autoApply)
|
|
581
|
+
if (this.autoApply)
|
|
583
582
|
this.container.addClass('auto-apply');
|
|
584
|
-
}
|
|
585
583
|
|
|
586
584
|
if (this.singleDatePicker) {
|
|
587
585
|
this.container.addClass('single');
|
|
@@ -675,7 +673,7 @@
|
|
|
675
673
|
} else if (startDate instanceof Date) {
|
|
676
674
|
this.startDate = DateTime.fromJSDate(startDate);
|
|
677
675
|
} else {
|
|
678
|
-
throw RangeError(`
|
|
676
|
+
throw RangeError(`The 'startDate' must be a luxon.DateTime or Date or string`);
|
|
679
677
|
}
|
|
680
678
|
} else if (typeof startDate === 'string') {
|
|
681
679
|
const format = typeof this.locale.format === 'string' ? this.locale.format : DateTime.parseFormatForOpts(this.locale.format);
|
|
@@ -684,7 +682,8 @@
|
|
|
684
682
|
} else if (DateTime.fromFormat(startDate, format, { locale: DateTime.now().locale }).isValid) {
|
|
685
683
|
this.startDate = DateTime.fromFormat(startDate, format, { locale: DateTime.now().locale });
|
|
686
684
|
} else {
|
|
687
|
-
|
|
685
|
+
const invalid = DateTime.fromFormat(startDate, format, { locale: DateTime.now().locale }).invalidExplanation;
|
|
686
|
+
throw RangeError(`The 'startDate' is not a valid string: ${invalid}`);
|
|
688
687
|
}
|
|
689
688
|
}
|
|
690
689
|
} else {
|
|
@@ -725,7 +724,7 @@
|
|
|
725
724
|
} else if (endDate instanceof Date) {
|
|
726
725
|
this.endDate = DateTime.fromJSDate(endDate);
|
|
727
726
|
} else {
|
|
728
|
-
throw RangeError(`
|
|
727
|
+
throw RangeError(`The 'endDate' must be a luxon.DateTime or Date or string`);
|
|
729
728
|
}
|
|
730
729
|
} else if (typeof endDate === 'string') {
|
|
731
730
|
const format = typeof this.locale.format === 'string' ? this.locale.format : DateTime.parseFormatForOpts(this.locale.format);
|
|
@@ -734,7 +733,8 @@
|
|
|
734
733
|
} else if (DateTime.fromFormat(endDate, format, { locale: DateTime.now().locale }).isValid) {
|
|
735
734
|
this.endDate = DateTime.fromFormat(endDate, format, { locale: DateTime.now().locale });
|
|
736
735
|
} else {
|
|
737
|
-
|
|
736
|
+
const invalid = DateTime.fromFormat(endDate, format, { locale: DateTime.now().locale }).invalidExplanation;
|
|
737
|
+
throw RangeError(`The 'endDate' is not a valid string: ${invalid}`);
|
|
738
738
|
}
|
|
739
739
|
}
|
|
740
740
|
} else {
|
|
@@ -788,6 +788,9 @@
|
|
|
788
788
|
}
|
|
789
789
|
},
|
|
790
790
|
|
|
791
|
+
logDate: function (date) {
|
|
792
|
+
return this.timePicker ? date.toISO({ suppressMilliseconds: true }) : date.toISODate();
|
|
793
|
+
},
|
|
791
794
|
|
|
792
795
|
/**
|
|
793
796
|
* @typedef constraintOptions
|
|
@@ -801,7 +804,6 @@
|
|
|
801
804
|
* @property {boolean} invalidTime=false If `true` then and if `invalidTime` return `true`, then an error is logged to console
|
|
802
805
|
* @property {boolean} writeWarning=true If `true` then a warning is written to console if `startDate` or `endDate` is modified
|
|
803
806
|
* with the exception of rounding due to `timePickerStepSize`.
|
|
804
|
-
|
|
805
807
|
*/
|
|
806
808
|
|
|
807
809
|
/**
|
|
@@ -819,7 +821,7 @@
|
|
|
819
821
|
* constrainDate({span: false, invalidDate: true, invalidTime: true}) =>
|
|
820
822
|
* { startDate: {stepped: ..., modified: [{old: ... new: ..., reason: 'minDate'}], isInvalidDate: true, isInvalidTime: false}, endDate: {stepped: ..., isInvalidDate: false, isInvalidTime: true} } ]
|
|
821
823
|
*/
|
|
822
|
-
constrainDate: function ({ minMax = true, span = true, stepSize = true, invalidDate = false, invalidTime = false, writeWarning =
|
|
824
|
+
constrainDate: function ({ minMax = true, span = true, stepSize = true, invalidDate = false, invalidTime = false, writeWarning = this.warnings } = {}, range) {
|
|
823
825
|
const name = range === undefined ? null : range[0];
|
|
824
826
|
const nLog = range === undefined ? '' : ` of range '${name}'`;
|
|
825
827
|
let startDate = range === undefined ? this.startDate : range[1];
|
|
@@ -834,47 +836,43 @@
|
|
|
834
836
|
if (invalidTime)
|
|
835
837
|
result.startDate.isInvalidTime = false;
|
|
836
838
|
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
|
|
842
|
-
|
|
843
|
-
|
|
839
|
+
if (stepSize) {
|
|
840
|
+
let modified = { old: startDate, reason: stepSize && this.timePicker ? 'timePickerStepSize' : 'No timePicker' };
|
|
841
|
+
if (this.timePicker) {
|
|
842
|
+
// Round time to step size
|
|
843
|
+
const secs = this.timePickerStepSize.as('seconds');
|
|
844
|
+
startDate = DateTime.fromSeconds(secs * Math.round(startDate.toSeconds() / secs));
|
|
845
|
+
} else {
|
|
846
|
+
startDate = startDate.startOf('day');
|
|
847
|
+
}
|
|
848
|
+
modified.new = startDate;
|
|
849
|
+
if (modified.new != modified.old)
|
|
850
|
+
result.startDate.modified.push(modified);
|
|
844
851
|
}
|
|
845
|
-
modified.new = startDate;
|
|
846
|
-
if (modified.new != modified.old)
|
|
847
|
-
result.startDate.modified.push(modified);
|
|
848
852
|
|
|
849
853
|
|
|
850
854
|
if (minMax) {
|
|
851
855
|
if (this.minDate && startDate < this.minDate) {
|
|
856
|
+
// If the startDate is earlier than minDate option, shift the startDate to allowable date
|
|
852
857
|
let modified = { old: startDate, reason: 'minDate' };
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
startDate = startDate.plus(this.timePickerStepSize);
|
|
856
|
-
} else {
|
|
857
|
-
startDate = this.minDate;
|
|
858
|
-
}
|
|
858
|
+
while (startDate < this.minDate)
|
|
859
|
+
startDate = startDate.plus(this.timePicker ? this.timePickerStepSize : { days: 1 });
|
|
859
860
|
modified.new = startDate;
|
|
860
861
|
if (modified.new != modified.old) {
|
|
861
862
|
result.startDate.modified.push(modified);
|
|
862
863
|
if (writeWarning)
|
|
863
|
-
console.warn(`Set startDate${nLog} to ${this.
|
|
864
|
+
console.warn(`Set 'startDate'${nLog} to ${this.logDate(startDate)} due to 'minDate'`);
|
|
864
865
|
}
|
|
865
866
|
} else if (this.maxDate && startDate > this.maxDate) {
|
|
867
|
+
// If the startDate is later than maxDate option, shift the startDate to allowable date
|
|
866
868
|
let modified = { old: startDate, reason: 'maxDate' };
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
startDate = startDate.minus(this.timePickerStepSize);
|
|
870
|
-
} else {
|
|
871
|
-
startDate = this.maxDate.startOf('day');
|
|
872
|
-
}
|
|
869
|
+
while (startDate > this.maxDate)
|
|
870
|
+
startDate = startDate.minus(this.timePicker ? this.timePickerStepSize : { days: 1 });
|
|
873
871
|
modified.new = startDate;
|
|
874
872
|
if (modified.new != modified.old) {
|
|
875
873
|
result.startDate.modified.push(modified);
|
|
876
874
|
if (writeWarning)
|
|
877
|
-
console.warn(`Set startDate${nLog} to ${this.
|
|
875
|
+
console.warn(`Set 'startDate'${nLog} to ${this.logDate(startDate)} due to 'maxDate'`);
|
|
878
876
|
}
|
|
879
877
|
}
|
|
880
878
|
}
|
|
@@ -892,7 +890,7 @@
|
|
|
892
890
|
if (invalidDate && this.isInvalidDate(startDate)) {
|
|
893
891
|
result.startDate.isInvalidDate = true;
|
|
894
892
|
if (writeWarning)
|
|
895
|
-
console.warn(`The startDate${nLog} ${
|
|
893
|
+
console.warn(`The 'startDate'${nLog} ${this.logDate(startDate)} is invalid by 'isInvalidDate'`);
|
|
896
894
|
}
|
|
897
895
|
|
|
898
896
|
if (invalidTime && this.timePicker) {
|
|
@@ -900,7 +898,7 @@
|
|
|
900
898
|
if (this.isInvalidTime(startDate, unit, 'start'))
|
|
901
899
|
result.startDate.isInvalidTime = true;
|
|
902
900
|
if (writeWarning)
|
|
903
|
-
console.warn(`The startDate${nLog} ${
|
|
901
|
+
console.warn(`The 'startDate'${nLog} ${this.logDate(startDate)} ${unit} is invalid by 'isInvalidTime'`);
|
|
904
902
|
}
|
|
905
903
|
}
|
|
906
904
|
|
|
@@ -927,88 +925,75 @@
|
|
|
927
925
|
if (invalidTime)
|
|
928
926
|
result.endDate.isInvalidTime = false;
|
|
929
927
|
|
|
930
|
-
|
|
931
|
-
|
|
932
|
-
|
|
933
|
-
|
|
934
|
-
|
|
935
|
-
|
|
936
|
-
|
|
928
|
+
if (stepSize) {
|
|
929
|
+
let modified = { old: endDate, reason: stepSize && this.timePicker ? 'timePickerStepSize' : 'No timePicker' };
|
|
930
|
+
if (this.timePicker) {
|
|
931
|
+
// Round time to step size
|
|
932
|
+
const secs = this.timePickerStepSize.as('seconds');
|
|
933
|
+
endDate = DateTime.fromSeconds(secs * Math.round(endDate.toSeconds() / secs));
|
|
934
|
+
} else {
|
|
935
|
+
endDate = endDate.endOf('day');
|
|
936
|
+
}
|
|
937
|
+
modified.new = endDate;
|
|
938
|
+
if (modified.new != modified.old)
|
|
939
|
+
result.endDate.modified.push(modified);
|
|
937
940
|
}
|
|
938
|
-
modified.new = endDate;
|
|
939
|
-
if (modified.new != modified.old)
|
|
940
|
-
result.endDate.modified.push(modified);
|
|
941
|
-
|
|
942
941
|
|
|
943
942
|
if (minMax) {
|
|
944
943
|
if (this.maxDate && endDate > this.maxDate) {
|
|
944
|
+
// If the endDate is later than maxDate option, shorten the range to the allowable period.
|
|
945
945
|
let modified = { old: endDate, reason: 'maxDate' };
|
|
946
|
-
|
|
947
|
-
|
|
948
|
-
endDate = endDate.minus(this.timePickerStepSize);
|
|
949
|
-
} else {
|
|
950
|
-
endDate = this.maxDate.endOf('day');
|
|
951
|
-
}
|
|
946
|
+
while (endDate > this.maxDate)
|
|
947
|
+
endDate = endDate.minus(this.timePicker ? this.timePickerStepSize : { days: 1 });
|
|
952
948
|
modified.new = endDate;
|
|
953
949
|
if (modified.new != modified.old) {
|
|
954
950
|
result.endDate.modified.push(modified);
|
|
955
951
|
if (writeWarning)
|
|
956
|
-
console.warn(`Set endDate${nLog} to ${this.
|
|
952
|
+
console.warn(`Set 'endDate'${nLog} to ${this.logDate(endDate)} due to 'maxDate'`);
|
|
957
953
|
}
|
|
958
954
|
} else if (this.minDate && endDate < this.minDate) {
|
|
955
|
+
// If the endDate is earlier than minDate option, shorten the range to the allowable period.
|
|
959
956
|
let modified = { old: endDate, reason: 'minDate' };
|
|
960
|
-
|
|
961
|
-
|
|
962
|
-
endDate = endDate.plus(this.timePickerStepSize);
|
|
963
|
-
} else {
|
|
964
|
-
endDate = this.minDate;
|
|
965
|
-
}
|
|
957
|
+
while (endDate < this.minDate)
|
|
958
|
+
endDate = endDate.plus(this.timePicker ? this.timePickerStepSize : { days: 1 });
|
|
966
959
|
modified.new = endDate;
|
|
967
960
|
if (modified.new != modified.old) {
|
|
968
961
|
result.endDate.modified.push(modified);
|
|
969
962
|
if (writeWarning)
|
|
970
|
-
console.warn(`Set endDate${nLog} to ${this.
|
|
963
|
+
console.warn(`Set 'endDate'${nLog} to ${this.logDate(endDate)} due to 'minDate'`);
|
|
971
964
|
}
|
|
972
965
|
}
|
|
973
966
|
}
|
|
974
967
|
|
|
975
968
|
if (span) {
|
|
976
969
|
if (this.maxSpan) {
|
|
977
|
-
// If the
|
|
970
|
+
// If the endDate exceeds those allowed by the maxSpan option, shorten the range to the allowable period.
|
|
978
971
|
const maxDate = startDate.plus(this.maxSpan);
|
|
979
972
|
if (endDate > maxDate) {
|
|
980
973
|
let modified = { old: endDate, reason: 'maxSpan' };
|
|
981
|
-
|
|
982
|
-
|
|
983
|
-
endDate = endDate.minus(this.timePickerStepSize);
|
|
984
|
-
} else {
|
|
985
|
-
endDate = maxDate.endOf('day');
|
|
986
|
-
}
|
|
974
|
+
while (endDate > maxDate)
|
|
975
|
+
endDate = endDate.minus(this.timePicker ? this.timePickerStepSize : { days: 1 });
|
|
987
976
|
modified.new = endDate;
|
|
988
977
|
if (modified.new != modified.old) {
|
|
989
978
|
result.endDate.modified.push(modified);
|
|
990
979
|
if (writeWarning)
|
|
991
|
-
console.warn(`Set endDate${nLog} to ${this.
|
|
980
|
+
console.warn(`Set 'endDate'${nLog} to ${this.logDate(endDate)} due to 'maxSpan'`);
|
|
992
981
|
}
|
|
993
982
|
}
|
|
994
983
|
}
|
|
995
984
|
|
|
996
985
|
if (this.minSpan) {
|
|
997
|
-
// If the
|
|
986
|
+
// If the endDate falls below those allowed by the minSpan option, expand the range to the allowable period.
|
|
998
987
|
const minDate = startDate.plus(this.minSpan);
|
|
999
988
|
if (endDate < minDate) {
|
|
1000
989
|
let modified = { old: endDate, reason: 'minSpan' };
|
|
1001
|
-
|
|
1002
|
-
|
|
1003
|
-
endDate = endDate.plus(this.timePickerStepSize);
|
|
1004
|
-
} else {
|
|
1005
|
-
endDate = minDate.endOf('day');
|
|
1006
|
-
}
|
|
990
|
+
while (endDate < minDate)
|
|
991
|
+
endDate = endDate.plus(this.timePicker ? this.timePickerStepSize : { days: 1 });
|
|
1007
992
|
modified.new = endDate;
|
|
1008
993
|
if (modified.new != modified.old) {
|
|
1009
994
|
result.endDate.modified.push(modified);
|
|
1010
995
|
if (writeWarning)
|
|
1011
|
-
console.warn(`Set endDate${nLog} to ${this.
|
|
996
|
+
console.warn(`Set 'endDate'${nLog} to ${this.logDate(endDate)} due to 'minSpan'`);
|
|
1012
997
|
}
|
|
1013
998
|
}
|
|
1014
999
|
}
|
|
@@ -1017,7 +1002,7 @@
|
|
|
1017
1002
|
if (invalidDate && this.isInvalidDate(endDate)) {
|
|
1018
1003
|
result.endDate.isInvalidDate = true;
|
|
1019
1004
|
if (writeWarning)
|
|
1020
|
-
console.warn(`The endDate${nLog} ${
|
|
1005
|
+
console.warn(`The 'endDate'${nLog} ${this.logDate(endDate)} is invalid by 'isInvalidDate'`);
|
|
1021
1006
|
}
|
|
1022
1007
|
|
|
1023
1008
|
if (invalidTime && this.timePicker) {
|
|
@@ -1025,7 +1010,7 @@
|
|
|
1025
1010
|
if (this.isInvalidTime(endDate, unit, 'end'))
|
|
1026
1011
|
result.endDate.isInvalidTime = true;
|
|
1027
1012
|
if (writeWarning)
|
|
1028
|
-
console.warn(`The endDate${nLog} ${
|
|
1013
|
+
console.warn(`The 'endDate'${nLog} ${this.logDate(endDate)} ${unit} is invalid by 'isInvalidTime'`);
|
|
1029
1014
|
}
|
|
1030
1015
|
}
|
|
1031
1016
|
|