daterangepicker-4.x 4.2.5 → 4.3.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/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.2.5/daterangepicker.min.js"></script>
22
- <link type="text/css" href="https://cdn.jsdelivr.net/npm/daterangepicker-4.x@4.2.5/daterangepicker.min.css" rel="stylesheet" />
21
+ <script type="text/javascript" src="https://cdn.jsdelivr.net/npm/daterangepicker-4.x@4.3.0/daterangepicker.min.js"></script>
22
+ <link type="text/css" href="https://cdn.jsdelivr.net/npm/daterangepicker-4.x@4.3.0/daterangepicker.min.css" rel="stylesheet" />
23
23
 
24
24
  <input type="text" id="daterange" />
25
25
 
@@ -339,9 +339,9 @@ When `startDate` or `endDate` are modified, then a warning is written to console
339
339
  **Example**
340
340
  ```js
341
341
  constrainDate({}, [DateTime.fromISO('2025-02-03'), DateTime.fromISO('2025-02-25')]) =>
342
- [ DateTime.fromISO('2025-02-05'), DateTime.fromISO('2025-02-20'), { startDate: {modified: true}, endDate: {modified: true} } ]
342
+ [ DateTime.fromISO('2025-02-05'), DateTime.fromISO('2025-02-20'), { startDate: { stepped: ... }, endDate: { stepped: ..., modified: [{old: ... new: ..., reason: 'minSpan'}] } } ]
343
343
  constrainDate({span: false, invalidDate: true, invalidTime: true}) =>
344
- { startDate: {modified: true, isInvalidDate: true, isInvalidTime: false}, endDate: {modified: false, isInvalidDate: false, isInvalidTime: true} } ]
344
+ { startDate: {stepped: ..., modified: [{old: ... new: ..., reason: 'minDate'}], isInvalidDate: true, isInvalidTime: false}, endDate: {stepped: ..., isInvalidDate: false, isInvalidTime: true} } ]
345
345
  ```
346
346
  <a name="DateRangePicker+updateView"></a>
347
347
 
@@ -531,7 +531,7 @@ Options for DateRangePicker
531
531
  | minYear | <code>number</code> | | Default: `DateTime.now().minus({year:100}).year`<br/>The minimum year shown in the dropdowns when `showDropdowns: true` |
532
532
  | maxYear | <code>number</code> | | Default: `DateTime.now().plus({year:100}).year`<br/>The maximum year shown in the dropdowns when `showDropdowns: true` |
533
533
  | showWeekNumbers | <code>boolean</code> | <code>false</code> | Show **localized** week numbers at the start of each week on the calendars |
534
- | showISOWeekNumbers | <code>boolean</code> | <code>false</code> | Show **ISO** week numbers at the start of each week on the calendars |
534
+ | showISOWeekNumbers | <code>boolean</code> | <code>false</code> | Show **ISO** week numbers at the start of each week on the calendars.<br/> Takes precedence over localized `showWeekNumbers` |
535
535
  | timePicker | <code>boolean</code> | <code>false</code> | Adds select boxes to choose times in addition to dates |
536
536
  | timePicker24Hour | <code>boolean</code> | <code>true</code> | Use 24-hour instead of 12-hour times, removing the AM/PM selection |
537
537
  | timePickerStepSize | [<code>Duration</code>](https://moment.github.io/luxon/api-docs/index.html#duration) \| <code>string</code> \| <code>number</code> | | Default: `Duration.fromObject({minutes:1})`<br/>Set the time picker step size.<br/> Must be a `luxon.Duration` or the number of seconds or a string according to [ISO-8601](ISO-8601) duration.<br/> Valid values are 1,2,3,4,5,6,10,12,15,20,30 for `Duration.fromObject({seconds: ...})` and `Duration.fromObject({minutes: ...})` and 1,2,3,4,6,(8,12) for `Duration.fromObject({hours: ...})`.<br/> Duration must be greater than `minSpan` and smaller than `maxSpan`.<br/> For example `timePickerStepSize: 600` will disable time picker seconds and time picker minutes are set to step size of 10 Minutes.<br/> Overwrites `timePickerIncrement` and `timePickerSeconds` |
@@ -73,7 +73,8 @@
73
73
  * @property {number} minYear - Default: `DateTime.now().minus({year:100}).year`<br/>The minimum year shown in the dropdowns when `showDropdowns: true`
74
74
  * @property {number} maxYear - Default: `DateTime.now().plus({year:100}).year`<br/>The maximum year shown in the dropdowns when `showDropdowns: true`
75
75
  * @property {boolean} showWeekNumbers=false - Show **localized** week numbers at the start of each week on the calendars
76
- * @property {boolean} showISOWeekNumbers=false - Show **ISO** week numbers at the start of each week on the calendars
76
+ * @property {boolean} showISOWeekNumbers=false - Show **ISO** week numbers at the start of each week on the calendars.<br/>
77
+ * Takes precedence over localized `showWeekNumbers`
77
78
 
78
79
  * @property {boolean} timePicker=false - Adds select boxes to choose times in addition to dates
79
80
  * @property {boolean} timePicker24Hour=true - Use 24-hour instead of 12-hour times, removing the AM/PM selection
@@ -201,19 +202,12 @@
201
202
  this.isInvalidTime = null;
202
203
  this.isCustomDate = null;
203
204
  this.onOutsideClick = 'apply';
204
- this.ranges = {};
205
-
206
- this.opens = 'right';
207
- if (this.element.hasClass('pull-right'))
208
- this.opens = 'left';
209
-
210
- this.drops = 'down';
211
- if (this.element.hasClass('dropup'))
212
- this.drops = 'up';
213
-
205
+ this.opens = this.element.hasClass('pull-right') ? 'left' : 'right';
206
+ this.drops = this.element.hasClass('dropup') ? 'up' : 'down';
214
207
  this.buttonClasses = 'btn btn-sm';
215
208
  this.applyButtonClasses = 'btn-primary';
216
209
  this.cancelButtonClasses = 'btn-default';
210
+ this.ranges = {};
217
211
 
218
212
  this.locale = {
219
213
  direction: 'ltr',
@@ -273,6 +267,10 @@
273
267
  //
274
268
 
275
269
  if (typeof options.locale === 'object') {
270
+ for (let key of ['separator', 'applyLabel', 'cancelLabel', 'weekLabel']) {
271
+ if (typeof options.locale[key] === 'string')
272
+ this.locale[key] = options.locale[key];
273
+ }
276
274
 
277
275
  if (typeof options.locale.direction === 'string') {
278
276
  if (['rtl', 'ltr'].includes(options.locale.direction))
@@ -284,9 +282,6 @@
284
282
  if (['string', 'object'].includes(typeof options.locale.format))
285
283
  this.locale.format = options.locale.format;
286
284
 
287
- if (typeof options.locale.separator === 'string')
288
- this.locale.separator = options.locale.separator;
289
-
290
285
  if (Array.isArray(options.locale.daysOfWeek)) {
291
286
  if (options.locale.daysOfWeek.some(x => typeof x !== 'string'))
292
287
  console.error(`Option 'options.locale.daysOfWeek' must be an array of strings`)
@@ -304,15 +299,6 @@
304
299
  if (typeof options.locale.firstDay === 'number')
305
300
  this.locale.firstDay = options.locale.firstDay;
306
301
 
307
- if (typeof options.locale.applyLabel === 'string')
308
- this.locale.applyLabel = options.locale.applyLabel;
309
-
310
- if (typeof options.locale.cancelLabel === 'string')
311
- this.locale.cancelLabel = options.locale.cancelLabel;
312
-
313
- if (typeof options.locale.weekLabel === 'string')
314
- this.locale.weekLabel = options.locale.weekLabel;
315
-
316
302
  if (typeof options.locale.customRangeLabel === 'string') {
317
303
  //Support unicode chars in the custom range name.
318
304
  var elem = document.createElement('textarea');
@@ -326,14 +312,28 @@
326
312
  }
327
313
  this.container.addClass(this.locale.direction);
328
314
 
329
- if (typeof options.singleDatePicker === 'boolean')
330
- this.singleDatePicker = options.singleDatePicker;
315
+ for (let key of ['timePicker', 'singleDatePicker', 'timePicker24Hour', 'showWeekNumbers', 'showISOWeekNumbers',
316
+ 'showDropdowns', 'linkedCalendars', 'showCustomRangeLabel', 'alwaysShowCalendars', 'autoApply', 'autoUpdateInput']) {
317
+ if (typeof options[key] === 'boolean')
318
+ this[key] = options[key];
319
+ }
320
+
321
+ for (let key of ['applyButtonClasses', 'cancelButtonClasses']) {
322
+ if (typeof options[key] === 'string')
323
+ this[key] = options[key];
324
+ }
331
325
 
332
- if (typeof options.timePicker === 'boolean')
333
- this.timePicker = options.timePicker;
326
+ for (let key of ['minYear', 'maxYear']) {
327
+ if (typeof options[key] === 'number')
328
+ this[key] = options[key];
329
+ }
334
330
 
335
- if (typeof options.timePicker24Hour === 'boolean')
336
- this.timePicker24Hour = options.timePicker24Hour;
331
+ for (let key of ['isInvalidDate', 'isInvalidTime', 'isCustomDate']) {
332
+ if (typeof options[key] === 'function')
333
+ this[key] = options[key]
334
+ else
335
+ this[key] = function () { return false };
336
+ }
337
337
 
338
338
  if (typeof options.timePickerSeconds === 'boolean') // backward compatibility
339
339
  this.timePickerStepSize = Duration.fromObject({ [options.timePickerSeconds ? 'seconds' : 'minutes']: 1 });
@@ -402,7 +402,7 @@
402
402
  if (this.minSpan && this.maxSpan && this.minSpan > this.maxSpan) {
403
403
  this.minSpan = null;
404
404
  this.maxSpan = null;
405
- console.error(`Ignore option 'minSpan' and 'maxSpan', because 'minSpan' must be smaller than 'maxSpan'`);
405
+ console.warn(`Ignore option 'minSpan' and 'maxSpan', because 'minSpan' must be smaller than 'maxSpan'`);
406
406
  }
407
407
  }
408
408
 
@@ -472,17 +472,13 @@
472
472
  if (!this.startDate && this.initalMonth) {
473
473
  // No initial date selected
474
474
  this.endDate = null;
475
+ if (this.timePicker)
476
+ console.error(`Option 'initalMonth' works only with 'timePicker: false'`);
475
477
  } else {
476
- // Do some sanity checks on startDate for minDate, maxDate
478
+ // Do some sanity checks on startDate and endDate for minDate, maxDate, minSpan, maxSpan, etc.
477
479
  this.constrainDate();
478
480
  }
479
481
 
480
- if (typeof options.applyButtonClasses === 'string')
481
- this.applyButtonClasses = options.applyButtonClasses;
482
-
483
- if (typeof options.cancelButtonClasses === 'string')
484
- this.cancelButtonClasses = options.cancelButtonClasses;
485
-
486
482
  if (typeof options.opens === 'string') {
487
483
  if (['left', 'right', 'center'].includes(options.opens))
488
484
  this.opens = options.opens
@@ -497,57 +493,12 @@
497
493
  console.error(`Option 'options.drops' must be 'drop', 'down' or 'auto'`);
498
494
  }
499
495
 
500
- if (typeof options.showWeekNumbers === 'boolean')
501
- this.showWeekNumbers = options.showWeekNumbers;
502
-
503
- if (typeof options.showISOWeekNumbers === 'boolean')
504
- this.showISOWeekNumbers = options.showISOWeekNumbers;
505
-
506
496
  if (Array.isArray(options.buttonClasses)) {
507
497
  this.buttonClasses = options.buttonClasses.join(' ')
508
498
  } else if (typeof options.buttonClasses === 'string') {
509
499
  this.buttonClasses = options.buttonClasses;
510
500
  }
511
501
 
512
- if (typeof options.showDropdowns === 'boolean')
513
- this.showDropdowns = options.showDropdowns;
514
-
515
- if (typeof options.minYear === 'number')
516
- this.minYear = options.minYear;
517
-
518
- if (typeof options.maxYear === 'number')
519
- this.maxYear = options.maxYear;
520
-
521
- if (typeof options.showCustomRangeLabel === 'boolean')
522
- this.showCustomRangeLabel = options.showCustomRangeLabel;
523
-
524
- if (typeof options.autoApply === 'boolean')
525
- this.autoApply = options.autoApply;
526
-
527
- if (typeof options.autoUpdateInput === 'boolean')
528
- this.autoUpdateInput = options.autoUpdateInput;
529
-
530
- if (typeof options.linkedCalendars === 'boolean')
531
- this.linkedCalendars = options.linkedCalendars;
532
-
533
- if (typeof options.isInvalidDate === 'function')
534
- this.isInvalidDate = options.isInvalidDate
535
- else
536
- this.isInvalidDate = function () { return false };
537
-
538
- if (typeof options.isInvalidTime === 'function')
539
- this.isInvalidTime = options.isInvalidTime
540
- else
541
- this.isInvalidTime = function () { return false };
542
-
543
- if (typeof options.isCustomDate === 'function')
544
- this.isCustomDate = options.isCustomDate
545
- else
546
- this.isCustomDate = function () { return false };
547
-
548
- if (typeof options.alwaysShowCalendars === 'boolean')
549
- this.alwaysShowCalendars = options.alwaysShowCalendars;
550
-
551
502
  if (typeof options.onOutsideClick === 'string') {
552
503
  if (['cancel', 'apply'].includes(options.onOutsideClick))
553
504
  this.onOutsideClick = options.onOutsideClick
@@ -590,14 +541,14 @@
590
541
  continue;
591
542
 
592
543
  const validRange = this.constrainDate({ span: false }, [range, start, end]);
593
- options.ranges[range] = validRange;
544
+ options.ranges[range] = [validRange[0], validRange[1]];
594
545
 
595
546
  //Support unicode chars in the range names.
596
547
  var elem = document.createElement('textarea');
597
548
  elem.innerHTML = range;
598
549
  var rangeHtml = elem.value;
599
550
 
600
- this.ranges[rangeHtml] = validRange;
551
+ this.ranges[rangeHtml] = [validRange[0], validRange[1]];
601
552
  }
602
553
 
603
554
  var list = '<ul>';
@@ -637,14 +588,12 @@
637
588
  this.container.find('.drp-calendar.left').addClass('single');
638
589
  this.container.find('.drp-calendar.left').show();
639
590
  this.container.find('.drp-calendar.right').hide();
640
- if (!this.timePicker && this.autoApply) {
591
+ if (!this.timePicker && this.autoApply)
641
592
  this.container.addClass('auto-apply');
642
- }
643
593
  }
644
594
 
645
- if ((typeof options.ranges === 'undefined' && !this.singleDatePicker) || this.alwaysShowCalendars) {
595
+ if ((typeof options.ranges === 'undefined' && !this.singleDatePicker) || this.alwaysShowCalendars)
646
596
  this.container.addClass('show-calendar');
647
- }
648
597
 
649
598
  this.container.addClass('opens' + this.opens);
650
599
 
@@ -866,9 +815,9 @@
866
815
  * @returns {Array} - Corrected range as array of `[startDate, endDate, isInvalid]` when range is set, otherwise just `isInvalid` object
867
816
  * @example
868
817
  * constrainDate({}, [DateTime.fromISO('2025-02-03'), DateTime.fromISO('2025-02-25')]) =>
869
- * [ DateTime.fromISO('2025-02-05'), DateTime.fromISO('2025-02-20'), { startDate: {modified: true}, endDate: {modified: true} } ]
818
+ * [ DateTime.fromISO('2025-02-05'), DateTime.fromISO('2025-02-20'), { startDate: { stepped: ... }, endDate: { stepped: ..., modified: [{old: ... new: ..., reason: 'minSpan'}] } } ]
870
819
  * constrainDate({span: false, invalidDate: true, invalidTime: true}) =>
871
- * { startDate: {modified: true, isInvalidDate: true, isInvalidTime: false}, endDate: {modified: false, isInvalidDate: false, isInvalidTime: true} } ]
820
+ * { startDate: {stepped: ..., modified: [{old: ... new: ..., reason: 'minDate'}], isInvalidDate: true, isInvalidTime: false}, endDate: {stepped: ..., isInvalidDate: false, isInvalidTime: true} } ]
872
821
  */
873
822
  constrainDate: function ({ minMax = true, span = true, stepSize = true, invalidDate = false, invalidTime = false, writeWarning = true } = {}, range) {
874
823
  const name = range === undefined ? null : range[0];
@@ -879,12 +828,13 @@
879
828
  if (!startDate)
880
829
  return;
881
830
 
882
- let isInvalid = { startDate: { modified: false } };
831
+ let result = { startDate: { modified: [] } };
883
832
  if (invalidDate)
884
- isInvalid.startDate.isInvalidDate = false;
833
+ result.startDate.isInvalidDate = false;
885
834
  if (invalidTime)
886
- isInvalid.startDate.isInvalidTime = false;
835
+ result.startDate.isInvalidTime = false;
887
836
 
837
+ let modified = { old: startDate, reason: stepSize && this.timePicker ? 'timePickerStepSize' : 'No timePicker' };
888
838
  if (stepSize && this.timePicker) {
889
839
  // Round time to step size
890
840
  const secs = this.timePickerStepSize.as('seconds');
@@ -892,28 +842,40 @@
892
842
  } else {
893
843
  startDate = startDate.startOf('day');
894
844
  }
845
+ modified.new = startDate;
846
+ if (modified.new != modified.old)
847
+ result.startDate.modified.push(modified);
848
+
895
849
 
896
850
  if (minMax) {
897
851
  if (this.minDate && startDate < this.minDate) {
852
+ let modified = { old: startDate, reason: 'minDate' };
898
853
  if (this.timePicker) {
899
854
  while (startDate < this.minDate)
900
855
  startDate = startDate.plus(this.timePickerStepSize);
901
856
  } else {
902
857
  startDate = this.minDate;
903
858
  }
904
- isInvalid.startDate.modified = true;
905
- if (writeWarning)
906
- console.warn(`Set startDate${nLog} to ${this.timePicker ? startDate.toISO({ suppressMilliseconds: true }) : startDate.toISODate()} due to 'minDate'`);
859
+ modified.new = startDate;
860
+ if (modified.new != modified.old) {
861
+ result.startDate.modified.push(modified);
862
+ if (writeWarning)
863
+ console.warn(`Set startDate${nLog} to ${this.timePicker ? startDate.toISO({ suppressMilliseconds: true }) : startDate.toISODate()} due to 'minDate'`);
864
+ }
907
865
  } else if (this.maxDate && startDate > this.maxDate) {
866
+ let modified = { old: startDate, reason: 'maxDate' };
908
867
  if (this.timePicker) {
909
868
  while (startDate > this.maxDate)
910
869
  startDate = startDate.minus(this.timePickerStepSize);
911
870
  } else {
912
871
  startDate = this.maxDate.startOf('day');
913
872
  }
914
- isInvalid.startDate.modified = true;
915
- if (writeWarning)
916
- console.warn(`Set startDate${nLog} to ${this.timePicker ? startDate.toISO({ suppressMilliseconds: true }) : startDate.toISODate()} due to 'maxDate'`);
873
+ modified.new = startDate;
874
+ if (modified.new != modified.old) {
875
+ result.startDate.modified.push(modified);
876
+ if (writeWarning)
877
+ console.warn(`Set startDate${nLog} to ${this.timePicker ? startDate.toISO({ suppressMilliseconds: true }) : startDate.toISODate()} due to 'maxDate'`);
878
+ }
917
879
  }
918
880
  }
919
881
 
@@ -928,7 +890,7 @@
928
890
  }
929
891
 
930
892
  if (invalidDate && this.isInvalidDate(startDate)) {
931
- isInvalid.startDate.isInvalidDate = true;
893
+ result.startDate.isInvalidDate = true;
932
894
  if (writeWarning)
933
895
  console.warn(`The startDate${nLog} ${startDate.toISODate()} is invalid by 'isInvalidDate'`);
934
896
  }
@@ -936,34 +898,36 @@
936
898
  if (invalidTime && this.timePicker) {
937
899
  for (let unit of units) {
938
900
  if (this.isInvalidTime(startDate, unit, 'start'))
939
- isInvalid.startDate.isInvalidTime = true;
901
+ result.startDate.isInvalidTime = true;
940
902
  if (writeWarning)
941
903
  console.warn(`The startDate${nLog} ${startDate.toISO({ suppressMilliseconds: true })} ${unit} is invalid by 'isInvalidTime'`);
942
904
  }
943
905
  }
944
906
 
907
+ if (result.startDate.modified.length == 0)
908
+ delete result.startDate.modified;
909
+
945
910
  if (this.singleDatePicker) {
946
911
  endDate = startDate;
947
912
  if (range === undefined) {
948
913
  this.startDate = startDate;
949
914
  this.endDate = endDate;
950
- return isInvalid;
915
+ return result;
951
916
  } else {
952
- return [startDate, endDate, isInvalid];
917
+ return [startDate, endDate, result];
953
918
  }
954
919
  }
955
920
 
956
921
  if (endDate == null)
957
- return isInvalid;
922
+ return result;
958
923
 
959
- isInvalid.endDate = { modified: false };
924
+ result.endDate = { modified: [] };
960
925
  if (invalidDate)
961
- isInvalid.endDate.isInvalidDate = false;
926
+ result.endDate.isInvalidDate = false;
962
927
  if (invalidTime)
963
- isInvalid.endDate.isInvalidTime = false;
964
-
965
-
928
+ result.endDate.isInvalidTime = false;
966
929
 
930
+ modified = { old: endDate, reason: stepSize && this.timePicker ? 'timePickerStepSize' : 'No timePicker' };
967
931
  if (stepSize && this.timePicker) {
968
932
  // Round time to step size
969
933
  const secs = this.timePickerStepSize.as('seconds');
@@ -971,28 +935,40 @@
971
935
  } else {
972
936
  endDate = endDate.endOf('day');
973
937
  }
938
+ modified.new = endDate;
939
+ if (modified.new != modified.old)
940
+ result.endDate.modified.push(modified);
941
+
974
942
 
975
943
  if (minMax) {
976
944
  if (this.maxDate && endDate > this.maxDate) {
945
+ let modified = { old: endDate, reason: 'maxDate' };
977
946
  if (this.timePicker) {
978
947
  while (endDate > this.maxDate)
979
948
  endDate = endDate.minus(this.timePickerStepSize);
980
949
  } else {
981
950
  endDate = this.maxDate.endOf('day');
982
951
  }
983
- isInvalid.endDate.modified = true;
984
- if (writeWarning)
985
- console.warn(`Set endDate${nLog} to ${this.timePicker ? endDate.toISO({ suppressMilliseconds: true }) : endDate.toISODate()} due to 'maxDate'`);
952
+ modified.new = endDate;
953
+ if (modified.new != modified.old) {
954
+ result.endDate.modified.push(modified);
955
+ if (writeWarning)
956
+ console.warn(`Set endDate${nLog} to ${this.timePicker ? endDate.toISO({ suppressMilliseconds: true }) : endDate.toISODate()} due to 'maxDate'`);
957
+ }
986
958
  } else if (this.minDate && endDate < this.minDate) {
959
+ let modified = { old: endDate, reason: 'minDate' };
987
960
  if (this.timePicker) {
988
961
  while (endDate < this.minDate)
989
962
  endDate = endDate.plus(this.timePickerStepSize);
990
963
  } else {
991
964
  endDate = this.minDate;
992
965
  }
993
- isInvalid.endDate.modified = true;
994
- if (writeWarning)
995
- console.warn(`Set endDate${nLog} to ${this.timePicker ? endDate.toISO({ suppressMilliseconds: true }) : endDate.toISODate()} due to 'minDate'`);
966
+ modified.new = endDate;
967
+ if (modified.new != modified.old) {
968
+ result.endDate.modified.push(modified);
969
+ if (writeWarning)
970
+ console.warn(`Set endDate${nLog} to ${this.timePicker ? endDate.toISO({ suppressMilliseconds: true }) : endDate.toISODate()} due to 'minDate'`);
971
+ }
996
972
  }
997
973
  }
998
974
 
@@ -1001,15 +977,19 @@
1001
977
  // If the end date exceeds those allowed by the maxSpan option, shorten the range to the allowable period.
1002
978
  const maxDate = startDate.plus(this.maxSpan);
1003
979
  if (endDate > maxDate) {
980
+ let modified = { old: endDate, reason: 'maxSpan' };
1004
981
  if (this.timePicker) {
1005
982
  while (endDate > maxDate)
1006
983
  endDate = endDate.minus(this.timePickerStepSize);
1007
984
  } else {
1008
985
  endDate = maxDate.endOf('day');
1009
986
  }
1010
- isInvalid.endDate.modified = true;
1011
- if (writeWarning)
1012
- console.warn(`Set endDate${nLog} to ${this.timePicker ? endDate.toISO({ suppressMilliseconds: true }) : endDate.toISODate()} due to 'maxSpan'`);
987
+ modified.new = endDate;
988
+ if (modified.new != modified.old) {
989
+ result.endDate.modified.push(modified);
990
+ if (writeWarning)
991
+ console.warn(`Set endDate${nLog} to ${this.timePicker ? endDate.toISO({ suppressMilliseconds: true }) : endDate.toISODate()} due to 'maxSpan'`);
992
+ }
1013
993
  }
1014
994
  }
1015
995
 
@@ -1017,16 +997,16 @@
1017
997
  // If the end date falls below those allowed by the minSpan option, expand the range to the allowable period.
1018
998
  const minDate = startDate.plus(this.minSpan);
1019
999
  if (endDate < minDate) {
1020
- if (this.minDate && endDate > this.minDate) {
1021
- throw RangeError(`Option${nLog} 'minDate' contradicts to option 'minSpan'`);
1000
+ let modified = { old: endDate, reason: 'minSpan' };
1001
+ if (this.timePicker) {
1002
+ while (endDate < minDate)
1003
+ endDate = endDate.plus(this.timePickerStepSize);
1022
1004
  } else {
1023
- if (this.timePicker) {
1024
- while (endDate < minDate)
1025
- endDate = endDate.plus(this.timePickerStepSize);
1026
- } else {
1027
- endDate = minDate.endOf('day');
1028
- }
1029
- iisInvalid.endDate.modified = true;
1005
+ endDate = minDate.endOf('day');
1006
+ }
1007
+ modified.new = endDate;
1008
+ if (modified.new != modified.old) {
1009
+ result.endDate.modified.push(modified);
1030
1010
  if (writeWarning)
1031
1011
  console.warn(`Set endDate${nLog} to ${this.timePicker ? endDate.toISO({ suppressMilliseconds: true }) : endDate.toISODate()} due to 'minSpan'`);
1032
1012
  }
@@ -1035,7 +1015,7 @@
1035
1015
  }
1036
1016
 
1037
1017
  if (invalidDate && this.isInvalidDate(endDate)) {
1038
- isInvalid.endDate.isInvalidDate = true;
1018
+ result.endDate.isInvalidDate = true;
1039
1019
  if (writeWarning)
1040
1020
  console.warn(`The endDate${nLog} ${endDate.toISODate()} is invalid by 'isInvalidDate'`);
1041
1021
  }
@@ -1043,18 +1023,21 @@
1043
1023
  if (invalidTime && this.timePicker) {
1044
1024
  for (let unit of units) {
1045
1025
  if (this.isInvalidTime(endDate, unit, 'end'))
1046
- isInvalid.endDate.isInvalidTime = true;
1026
+ result.endDate.isInvalidTime = true;
1047
1027
  if (writeWarning)
1048
1028
  console.warn(`The endDate${nLog} ${endDate.toISO({ suppressMilliseconds: true })} ${unit} is invalid by 'isInvalidTime'`);
1049
1029
  }
1050
1030
  }
1051
1031
 
1032
+ if (result.endDate.modified.length == 0)
1033
+ delete result.endDate.modified;
1034
+
1052
1035
  if (range === undefined) {
1053
1036
  this.startDate = startDate;
1054
1037
  this.endDate = endDate;
1055
- return isInvalid;
1038
+ return result;
1056
1039
  } else {
1057
- return [startDate, endDate, isInvalid];
1040
+ return [startDate, endDate, result];
1058
1041
  }
1059
1042
 
1060
1043
  },
@@ -1182,9 +1165,7 @@
1182
1165
  second = parseInt(this.container.find('.right .secondselect option:last').val(), 10);
1183
1166
  }
1184
1167
  }
1185
- //if (this.leftCalendar.month)
1186
1168
  this.leftCalendar.month = this.leftCalendar.month.set({ hour: hour, minute: minute, second: second });
1187
- //if (this.rightCalendar.month)
1188
1169
  this.rightCalendar.month = this.rightCalendar.month.set({ hour: hour, minute: minute, second: second });
1189
1170
  }
1190
1171
 
@@ -1209,7 +1190,7 @@
1209
1190
  //
1210
1191
  var calendar = side == 'left' ? this.leftCalendar : this.rightCalendar;
1211
1192
  if (calendar.month == null && !this.startDate && this.initalMonth)
1212
- calendar.month = this.initalMonth;
1193
+ calendar.month = this.initalMonth.startOf('month');
1213
1194
 
1214
1195
  const firstDay = calendar.month.startOf('month');
1215
1196
  const lastDay = calendar.month.endOf('month').startOf('day');
@@ -1228,21 +1209,10 @@
1228
1209
  while (theDate.weekday != this.locale.firstDay)
1229
1210
  theDate = theDate.minus({ day: 1 });
1230
1211
 
1231
- var row, col;
1232
- for (let i = 0, col = 0, row = 0; i < 42; i++, col++, theDate = theDate.plus({ day: 1 })) {
1233
- if (i > 0 && col % 7 === 0) {
1234
- col = 0;
1212
+ for (let col = 0, row = -1; col < 42; col++, theDate = theDate.plus({ day: 1 })) {
1213
+ if (col % 7 === 0)
1235
1214
  row++;
1236
- }
1237
- calendar[row][col] = theDate.set(time);
1238
-
1239
- // I have no clue why and how this shall be used in original code. Skip it, maybe I will find out later
1240
- /*if (this.minDate && calendar[row][col].hasSame(this.minDate, 'month') && calendar[row][col] < this.minDate && side == 'left')
1241
- calendar[row][col] = this.minDate;
1242
-
1243
- if (this.maxDate && calendar[row][col].hasSame(this.maxDate, 'month') && calendar[row][col] > this.maxDate && side == 'right')
1244
- calendar[row][col] = this.maxDate;
1245
- */
1215
+ calendar[row][col % 7] = theDate.set(time);
1246
1216
  }
1247
1217
 
1248
1218
  //make the calendar object available to hoverDate/clickDate
@@ -1339,16 +1309,16 @@
1339
1309
  if (this.endDate == null && this.minSpan)
1340
1310
  minLimit = this.startDate.plus(this.minSpan).startOf('day');
1341
1311
 
1342
- for (var row = 0; row < 6; row++) {
1312
+ for (let row = 0; row < 6; row++) {
1343
1313
  html += '<tr>';
1344
1314
 
1345
1315
  // add week number
1346
- if (this.showWeekNumbers)
1347
- html += '<td class="week">' + calendar[row][0].localWeekNumber + '</td>';
1348
- else if (this.showISOWeekNumbers)
1316
+ if (this.showISOWeekNumbers)
1349
1317
  html += '<td class="week">' + calendar[row][0].weekNumber + '</td>';
1318
+ else if (this.showWeekNumbers)
1319
+ html += '<td class="week">' + calendar[row][0].localWeekNumber + '</td>';
1350
1320
 
1351
- for (var col = 0; col < 7; col++) {
1321
+ for (let col = 0; col < 7; col++) {
1352
1322
 
1353
1323
  var classes = [];
1354
1324
 
@@ -1802,8 +1772,7 @@
1802
1772
  * @param {DateRangePicker} this - The daterangepicker object
1803
1773
  * @return {boolean} cancel - If `true`, then the picker remains visible
1804
1774
  */
1805
- const cancel = this.element.triggerHandler('beforeHide.daterangepicker', this);
1806
- if (cancel)
1775
+ if (this.element.triggerHandler('beforeHide.daterangepicker', this))
1807
1776
  return;
1808
1777
  $(document).off('.daterangepicker');
1809
1778
  $(window).off('.daterangepicker');
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "daterangepicker-4.x",
3
- "version": "4.2.5",
3
+ "version": "4.3.0",
4
4
  "description": "Date range picker with time component and pre-defined ranges",
5
5
  "main": "daterangepicker.js",
6
6
  "style": "daterangepicker.css",