daterangepicker-4.x 4.3.0 → 4.3.1
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 +86 -108
- 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.1/daterangepicker.min.js"></script>
|
|
22
|
+
<link type="text/css" href="https://cdn.jsdelivr.net/npm/daterangepicker-4.x@4.3.1/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;
|
|
@@ -466,7 +460,7 @@
|
|
|
466
460
|
this.endDate = this.startDate;
|
|
467
461
|
} else if (this.endDate < this.startDate) {
|
|
468
462
|
this.endDate = this.startDate;
|
|
469
|
-
console.warn(`Set endDate to ${this
|
|
463
|
+
console.warn(`Set 'endDate' to ${this - this.logDate(endDate)} because it was earlier than 'startDate'`);
|
|
470
464
|
}
|
|
471
465
|
|
|
472
466
|
if (!this.startDate && this.initalMonth) {
|
|
@@ -579,9 +573,8 @@
|
|
|
579
573
|
if (this.timePicker && this.autoApply)
|
|
580
574
|
this.autoApply = false;
|
|
581
575
|
|
|
582
|
-
if (this.autoApply)
|
|
576
|
+
if (this.autoApply)
|
|
583
577
|
this.container.addClass('auto-apply');
|
|
584
|
-
}
|
|
585
578
|
|
|
586
579
|
if (this.singleDatePicker) {
|
|
587
580
|
this.container.addClass('single');
|
|
@@ -788,6 +781,9 @@
|
|
|
788
781
|
}
|
|
789
782
|
},
|
|
790
783
|
|
|
784
|
+
logDate: function (date) {
|
|
785
|
+
return this.timePicker ? date.toISO({ suppressMilliseconds: true }) : date.toISODate();
|
|
786
|
+
},
|
|
791
787
|
|
|
792
788
|
/**
|
|
793
789
|
* @typedef constraintOptions
|
|
@@ -801,7 +797,6 @@
|
|
|
801
797
|
* @property {boolean} invalidTime=false If `true` then and if `invalidTime` return `true`, then an error is logged to console
|
|
802
798
|
* @property {boolean} writeWarning=true If `true` then a warning is written to console if `startDate` or `endDate` is modified
|
|
803
799
|
* with the exception of rounding due to `timePickerStepSize`.
|
|
804
|
-
|
|
805
800
|
*/
|
|
806
801
|
|
|
807
802
|
/**
|
|
@@ -819,7 +814,7 @@
|
|
|
819
814
|
* constrainDate({span: false, invalidDate: true, invalidTime: true}) =>
|
|
820
815
|
* { startDate: {stepped: ..., modified: [{old: ... new: ..., reason: 'minDate'}], isInvalidDate: true, isInvalidTime: false}, endDate: {stepped: ..., isInvalidDate: false, isInvalidTime: true} } ]
|
|
821
816
|
*/
|
|
822
|
-
constrainDate: function ({ minMax = true, span = true, stepSize = true, invalidDate = false, invalidTime = false, writeWarning =
|
|
817
|
+
constrainDate: function ({ minMax = true, span = true, stepSize = true, invalidDate = false, invalidTime = false, writeWarning = this.warnings } = {}, range) {
|
|
823
818
|
const name = range === undefined ? null : range[0];
|
|
824
819
|
const nLog = range === undefined ? '' : ` of range '${name}'`;
|
|
825
820
|
let startDate = range === undefined ? this.startDate : range[1];
|
|
@@ -834,47 +829,43 @@
|
|
|
834
829
|
if (invalidTime)
|
|
835
830
|
result.startDate.isInvalidTime = false;
|
|
836
831
|
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
|
|
842
|
-
|
|
843
|
-
|
|
832
|
+
if (stepSize) {
|
|
833
|
+
let modified = { old: startDate, reason: stepSize && this.timePicker ? 'timePickerStepSize' : 'No timePicker' };
|
|
834
|
+
if (this.timePicker) {
|
|
835
|
+
// Round time to step size
|
|
836
|
+
const secs = this.timePickerStepSize.as('seconds');
|
|
837
|
+
startDate = DateTime.fromSeconds(secs * Math.round(startDate.toSeconds() / secs));
|
|
838
|
+
} else {
|
|
839
|
+
startDate = startDate.startOf('day');
|
|
840
|
+
}
|
|
841
|
+
modified.new = startDate;
|
|
842
|
+
if (modified.new != modified.old)
|
|
843
|
+
result.startDate.modified.push(modified);
|
|
844
844
|
}
|
|
845
|
-
modified.new = startDate;
|
|
846
|
-
if (modified.new != modified.old)
|
|
847
|
-
result.startDate.modified.push(modified);
|
|
848
845
|
|
|
849
846
|
|
|
850
847
|
if (minMax) {
|
|
851
848
|
if (this.minDate && startDate < this.minDate) {
|
|
849
|
+
// If the startDate is earlier than minDate option, shift the startDate to allowable date
|
|
852
850
|
let modified = { old: startDate, reason: 'minDate' };
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
startDate = startDate.plus(this.timePickerStepSize);
|
|
856
|
-
} else {
|
|
857
|
-
startDate = this.minDate;
|
|
858
|
-
}
|
|
851
|
+
while (startDate < this.minDate)
|
|
852
|
+
startDate = startDate.plus(this.timePicker ? this.timePickerStepSize : { days: 1 });
|
|
859
853
|
modified.new = startDate;
|
|
860
854
|
if (modified.new != modified.old) {
|
|
861
855
|
result.startDate.modified.push(modified);
|
|
862
856
|
if (writeWarning)
|
|
863
|
-
console.warn(`Set startDate${nLog} to ${this.
|
|
857
|
+
console.warn(`Set 'startDate'${nLog} to ${this.logDate(startDate)} due to 'minDate'`);
|
|
864
858
|
}
|
|
865
859
|
} else if (this.maxDate && startDate > this.maxDate) {
|
|
860
|
+
// If the startDate is later than maxDate option, shift the startDate to allowable date
|
|
866
861
|
let modified = { old: startDate, reason: 'maxDate' };
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
startDate = startDate.minus(this.timePickerStepSize);
|
|
870
|
-
} else {
|
|
871
|
-
startDate = this.maxDate.startOf('day');
|
|
872
|
-
}
|
|
862
|
+
while (startDate > this.maxDate)
|
|
863
|
+
startDate = startDate.minus(this.timePicker ? this.timePickerStepSize : { days: 1 });
|
|
873
864
|
modified.new = startDate;
|
|
874
865
|
if (modified.new != modified.old) {
|
|
875
866
|
result.startDate.modified.push(modified);
|
|
876
867
|
if (writeWarning)
|
|
877
|
-
console.warn(`Set startDate${nLog} to ${this.
|
|
868
|
+
console.warn(`Set 'startDate'${nLog} to ${this.logDate(startDate)} due to 'maxDate'`);
|
|
878
869
|
}
|
|
879
870
|
}
|
|
880
871
|
}
|
|
@@ -892,7 +883,7 @@
|
|
|
892
883
|
if (invalidDate && this.isInvalidDate(startDate)) {
|
|
893
884
|
result.startDate.isInvalidDate = true;
|
|
894
885
|
if (writeWarning)
|
|
895
|
-
console.warn(`The startDate${nLog} ${
|
|
886
|
+
console.warn(`The 'startDate'${nLog} ${this.logDate(startDate)} is invalid by 'isInvalidDate'`);
|
|
896
887
|
}
|
|
897
888
|
|
|
898
889
|
if (invalidTime && this.timePicker) {
|
|
@@ -900,7 +891,7 @@
|
|
|
900
891
|
if (this.isInvalidTime(startDate, unit, 'start'))
|
|
901
892
|
result.startDate.isInvalidTime = true;
|
|
902
893
|
if (writeWarning)
|
|
903
|
-
console.warn(`The startDate${nLog} ${
|
|
894
|
+
console.warn(`The 'startDate'${nLog} ${this.logDate(startDate)} ${unit} is invalid by 'isInvalidTime'`);
|
|
904
895
|
}
|
|
905
896
|
}
|
|
906
897
|
|
|
@@ -927,88 +918,75 @@
|
|
|
927
918
|
if (invalidTime)
|
|
928
919
|
result.endDate.isInvalidTime = false;
|
|
929
920
|
|
|
930
|
-
|
|
931
|
-
|
|
932
|
-
|
|
933
|
-
|
|
934
|
-
|
|
935
|
-
|
|
936
|
-
|
|
921
|
+
if (stepSize) {
|
|
922
|
+
let modified = { old: endDate, reason: stepSize && this.timePicker ? 'timePickerStepSize' : 'No timePicker' };
|
|
923
|
+
if (this.timePicker) {
|
|
924
|
+
// Round time to step size
|
|
925
|
+
const secs = this.timePickerStepSize.as('seconds');
|
|
926
|
+
endDate = DateTime.fromSeconds(secs * Math.round(endDate.toSeconds() / secs));
|
|
927
|
+
} else {
|
|
928
|
+
endDate = endDate.endOf('day');
|
|
929
|
+
}
|
|
930
|
+
modified.new = endDate;
|
|
931
|
+
if (modified.new != modified.old)
|
|
932
|
+
result.endDate.modified.push(modified);
|
|
937
933
|
}
|
|
938
|
-
modified.new = endDate;
|
|
939
|
-
if (modified.new != modified.old)
|
|
940
|
-
result.endDate.modified.push(modified);
|
|
941
|
-
|
|
942
934
|
|
|
943
935
|
if (minMax) {
|
|
944
936
|
if (this.maxDate && endDate > this.maxDate) {
|
|
937
|
+
// If the endDate is later than maxDate option, shorten the range to the allowable period.
|
|
945
938
|
let modified = { old: endDate, reason: 'maxDate' };
|
|
946
|
-
|
|
947
|
-
|
|
948
|
-
endDate = endDate.minus(this.timePickerStepSize);
|
|
949
|
-
} else {
|
|
950
|
-
endDate = this.maxDate.endOf('day');
|
|
951
|
-
}
|
|
939
|
+
while (endDate > this.maxDate)
|
|
940
|
+
endDate = endDate.minus(this.timePicker ? this.timePickerStepSize : { days: 1 });
|
|
952
941
|
modified.new = endDate;
|
|
953
942
|
if (modified.new != modified.old) {
|
|
954
943
|
result.endDate.modified.push(modified);
|
|
955
944
|
if (writeWarning)
|
|
956
|
-
console.warn(`Set endDate${nLog} to ${this.
|
|
945
|
+
console.warn(`Set 'endDate'${nLog} to ${this.logDate(endDate)} due to 'maxDate'`);
|
|
957
946
|
}
|
|
958
947
|
} else if (this.minDate && endDate < this.minDate) {
|
|
948
|
+
// If the endDate is earlier than minDate option, shorten the range to the allowable period.
|
|
959
949
|
let modified = { old: endDate, reason: 'minDate' };
|
|
960
|
-
|
|
961
|
-
|
|
962
|
-
endDate = endDate.plus(this.timePickerStepSize);
|
|
963
|
-
} else {
|
|
964
|
-
endDate = this.minDate;
|
|
965
|
-
}
|
|
950
|
+
while (endDate < this.minDate)
|
|
951
|
+
endDate = endDate.plus(this.timePicker ? this.timePickerStepSize : { days: 1 });
|
|
966
952
|
modified.new = endDate;
|
|
967
953
|
if (modified.new != modified.old) {
|
|
968
954
|
result.endDate.modified.push(modified);
|
|
969
955
|
if (writeWarning)
|
|
970
|
-
console.warn(`Set endDate${nLog} to ${this.
|
|
956
|
+
console.warn(`Set 'endDate'${nLog} to ${this.logDate(endDate)} due to 'minDate'`);
|
|
971
957
|
}
|
|
972
958
|
}
|
|
973
959
|
}
|
|
974
960
|
|
|
975
961
|
if (span) {
|
|
976
962
|
if (this.maxSpan) {
|
|
977
|
-
// If the
|
|
963
|
+
// If the endDate exceeds those allowed by the maxSpan option, shorten the range to the allowable period.
|
|
978
964
|
const maxDate = startDate.plus(this.maxSpan);
|
|
979
965
|
if (endDate > maxDate) {
|
|
980
966
|
let modified = { old: endDate, reason: 'maxSpan' };
|
|
981
|
-
|
|
982
|
-
|
|
983
|
-
endDate = endDate.minus(this.timePickerStepSize);
|
|
984
|
-
} else {
|
|
985
|
-
endDate = maxDate.endOf('day');
|
|
986
|
-
}
|
|
967
|
+
while (endDate > maxDate)
|
|
968
|
+
endDate = endDate.minus(this.timePicker ? this.timePickerStepSize : { days: 1 });
|
|
987
969
|
modified.new = endDate;
|
|
988
970
|
if (modified.new != modified.old) {
|
|
989
971
|
result.endDate.modified.push(modified);
|
|
990
972
|
if (writeWarning)
|
|
991
|
-
console.warn(`Set endDate${nLog} to ${this.
|
|
973
|
+
console.warn(`Set 'endDate'${nLog} to ${this.logDate(endDate)} due to 'maxSpan'`);
|
|
992
974
|
}
|
|
993
975
|
}
|
|
994
976
|
}
|
|
995
977
|
|
|
996
978
|
if (this.minSpan) {
|
|
997
|
-
// If the
|
|
979
|
+
// If the endDate falls below those allowed by the minSpan option, expand the range to the allowable period.
|
|
998
980
|
const minDate = startDate.plus(this.minSpan);
|
|
999
981
|
if (endDate < minDate) {
|
|
1000
982
|
let modified = { old: endDate, reason: 'minSpan' };
|
|
1001
|
-
|
|
1002
|
-
|
|
1003
|
-
endDate = endDate.plus(this.timePickerStepSize);
|
|
1004
|
-
} else {
|
|
1005
|
-
endDate = minDate.endOf('day');
|
|
1006
|
-
}
|
|
983
|
+
while (endDate < minDate)
|
|
984
|
+
endDate = endDate.plus(this.timePicker ? this.timePickerStepSize : { days: 1 });
|
|
1007
985
|
modified.new = endDate;
|
|
1008
986
|
if (modified.new != modified.old) {
|
|
1009
987
|
result.endDate.modified.push(modified);
|
|
1010
988
|
if (writeWarning)
|
|
1011
|
-
console.warn(`Set endDate${nLog} to ${this.
|
|
989
|
+
console.warn(`Set 'endDate'${nLog} to ${this.logDate(endDate)} due to 'minSpan'`);
|
|
1012
990
|
}
|
|
1013
991
|
}
|
|
1014
992
|
}
|
|
@@ -1017,7 +995,7 @@
|
|
|
1017
995
|
if (invalidDate && this.isInvalidDate(endDate)) {
|
|
1018
996
|
result.endDate.isInvalidDate = true;
|
|
1019
997
|
if (writeWarning)
|
|
1020
|
-
console.warn(`The endDate${nLog} ${
|
|
998
|
+
console.warn(`The 'endDate'${nLog} ${this.logDate(endDate)} is invalid by 'isInvalidDate'`);
|
|
1021
999
|
}
|
|
1022
1000
|
|
|
1023
1001
|
if (invalidTime && this.timePicker) {
|
|
@@ -1025,7 +1003,7 @@
|
|
|
1025
1003
|
if (this.isInvalidTime(endDate, unit, 'end'))
|
|
1026
1004
|
result.endDate.isInvalidTime = true;
|
|
1027
1005
|
if (writeWarning)
|
|
1028
|
-
console.warn(`The endDate${nLog} ${
|
|
1006
|
+
console.warn(`The 'endDate'${nLog} ${this.logDate(endDate)} ${unit} is invalid by 'isInvalidTime'`);
|
|
1029
1007
|
}
|
|
1030
1008
|
}
|
|
1031
1009
|
|