daterangepicker-4.x 4.2.4 → 4.2.6
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 +47 -3
- package/daterangepicker.js +110 -120
- 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.2.
|
|
22
|
-
<link type="text/css" href="https://cdn.jsdelivr.net/npm/daterangepicker-4.x@4.2.
|
|
21
|
+
<script type="text/javascript" src="https://cdn.jsdelivr.net/npm/daterangepicker-4.x@4.2.6/daterangepicker.min.js"></script>
|
|
22
|
+
<link type="text/css" href="https://cdn.jsdelivr.net/npm/daterangepicker-4.x@4.2.6/daterangepicker.min.css" rel="stylesheet" />
|
|
23
23
|
|
|
24
24
|
<input type="text" id="daterange" />
|
|
25
25
|
|
|
@@ -202,6 +202,8 @@ use <a href="#event_timeChange.daterangepicker">"timeChange.daterangepicker
|
|
|
202
202
|
<dt><a href="#Range">Range</a> : <code>Object</code></dt>
|
|
203
203
|
<dd><p>A single predefined range</p>
|
|
204
204
|
</dd>
|
|
205
|
+
<dt><a href="#constraintOptions">constraintOptions</a> : <code>Object</code></dt>
|
|
206
|
+
<dd></dd>
|
|
205
207
|
<dt><a href="#callback">callback</a> : <code>function</code></dt>
|
|
206
208
|
<dd></dd>
|
|
207
209
|
</dl>
|
|
@@ -217,6 +219,7 @@ use <a href="#event_timeChange.daterangepicker">"timeChange.daterangepicker
|
|
|
217
219
|
* [.setStartDate(startDate, isValid)](#DateRangePicker+setStartDate)
|
|
218
220
|
* [.setEndDate(endDate, isValid)](#DateRangePicker+setEndDate)
|
|
219
221
|
* [.setPeriod(startDate, endDate, isValid)](#DateRangePicker+setPeriod)
|
|
222
|
+
* [.constrainDate(options, [range])](#DateRangePicker+constrainDate) ⇒ <code>Array</code>
|
|
220
223
|
* [.updateView()](#DateRangePicker+updateView)
|
|
221
224
|
* [.showCalendars()](#DateRangePicker+showCalendars)
|
|
222
225
|
* [.hideCalendars()](#DateRangePicker+hideCalendars)
|
|
@@ -314,6 +317,32 @@ const DateTime = luxon.DateTime;
|
|
|
314
317
|
const drp = $('#picker').data('daterangepicker');
|
|
315
318
|
drp.setPeriod(DateTime.now().startOf('week'), DateTime.now().startOf('week').plus({days: 10}));
|
|
316
319
|
```
|
|
320
|
+
<a name="DateRangePicker+constrainDate"></a>
|
|
321
|
+
|
|
322
|
+
### dateRangePicker.constrainDate(options, [range]) ⇒ <code>Array</code>
|
|
323
|
+
Validate `startDate` and `endDate` or `range` against `timePickerStepSize`, `minDate`, `maxDate`,
|
|
324
|
+
`minSpan`, `maxSpan`, `invalidDate` and `invalidTime` and modifies them, if needed.
|
|
325
|
+
When `startDate` or `endDate` are modified, then a warning is written to console by default.
|
|
326
|
+
|
|
327
|
+
**Kind**: instance method of [<code>DateRangePicker</code>](#DateRangePicker)
|
|
328
|
+
**Returns**: <code>Array</code> - - Corrected range as array of `[startDate, endDate, isInvalid]` when range is set, otherwise just `isInvalid` object
|
|
329
|
+
**Throws**:
|
|
330
|
+
|
|
331
|
+
- `RangeError` if 'minDate' contradicts to 'minSpan'
|
|
332
|
+
|
|
333
|
+
|
|
334
|
+
| Param | Type | Description |
|
|
335
|
+
| --- | --- | --- |
|
|
336
|
+
| options | [<code>constraintOptions</code>](#constraintOptions) | Defines which constraints shall be validated |
|
|
337
|
+
| [range] | <code>Array</code> | Used to check prefefined range instead of `startDate` and `endDate` => `[name, startDate, endDate]` When set, then function does not modify anything, just returning corrected range. |
|
|
338
|
+
|
|
339
|
+
**Example**
|
|
340
|
+
```js
|
|
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} } ]
|
|
343
|
+
constrainDate({span: false, invalidDate: true, invalidTime: true}) =>
|
|
344
|
+
{ startDate: {modified: true, isInvalidDate: true, isInvalidTime: false}, endDate: {modified: false, isInvalidDate: false, isInvalidTime: true} } ]
|
|
345
|
+
```
|
|
317
346
|
<a name="DateRangePicker+updateView"></a>
|
|
318
347
|
|
|
319
348
|
### dateRangePicker.updateView()
|
|
@@ -502,7 +531,7 @@ Options for DateRangePicker
|
|
|
502
531
|
| minYear | <code>number</code> | | Default: `DateTime.now().minus({year:100}).year`<br/>The minimum year shown in the dropdowns when `showDropdowns: true` |
|
|
503
532
|
| maxYear | <code>number</code> | | Default: `DateTime.now().plus({year:100}).year`<br/>The maximum year shown in the dropdowns when `showDropdowns: true` |
|
|
504
533
|
| showWeekNumbers | <code>boolean</code> | <code>false</code> | Show **localized** week numbers at the start of each week on the calendars |
|
|
505
|
-
| 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` |
|
|
506
535
|
| timePicker | <code>boolean</code> | <code>false</code> | Adds select boxes to choose times in addition to dates |
|
|
507
536
|
| timePicker24Hour | <code>boolean</code> | <code>true</code> | Use 24-hour instead of 12-hour times, removing the AM/PM selection |
|
|
508
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` |
|
|
@@ -576,6 +605,21 @@ A single predefined range
|
|
|
576
605
|
```js
|
|
577
606
|
{ Today: [DateTime.now().startOf('day'), DateTime.now().endOf('day')] }
|
|
578
607
|
```
|
|
608
|
+
<a name="constraintOptions"></a>
|
|
609
|
+
|
|
610
|
+
## constraintOptions : <code>Object</code>
|
|
611
|
+
**Kind**: global typedef
|
|
612
|
+
**Properties**
|
|
613
|
+
|
|
614
|
+
| Name | Type | Default | Description |
|
|
615
|
+
| --- | --- | --- | --- |
|
|
616
|
+
| stepSize | <code>boolean</code> | <code>true</code> | If `true`, then `startDate` and `endDate` are rounded to match `timePickerStepSize` (no warning) |
|
|
617
|
+
| minMax | <code>boolean</code> | <code>true</code> | If `true` then and if the `startDate` and `endDate` do not fall into `minDate` and `maxDate` then dates are shifted and a warning is written to console. |
|
|
618
|
+
| span | <code>boolean</code> | <code>true</code> | If `true` then and if the `startDate` and `endDate` do not fall into `minDate` and `maxSpan` then `endDate` is shifted and a warning is written to console. |
|
|
619
|
+
| invalidDate | <code>boolean</code> | <code>false</code> | If `true` then and if `invalidDate` return `true`, then an error is logged to console |
|
|
620
|
+
| invalidTime | <code>boolean</code> | <code>false</code> | If `true` then and if `invalidTime` return `true`, then an error is logged to console |
|
|
621
|
+
| writeWarning | <code>boolean</code> | <code>true</code> | If `true` then a warning is written to console if `startDate` or `endDate` is modified with the exception of rounding due to `timePickerStepSize`. |
|
|
622
|
+
|
|
579
623
|
<a name="callback"></a>
|
|
580
624
|
|
|
581
625
|
## callback : <code>function</code>
|
package/daterangepicker.js
CHANGED
|
@@ -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.
|
|
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
|
-
|
|
330
|
-
|
|
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
|
-
|
|
333
|
-
|
|
326
|
+
for (let key of ['minYear', 'maxYear']) {
|
|
327
|
+
if (typeof options[key] === 'number')
|
|
328
|
+
this[key] = options[key];
|
|
329
|
+
}
|
|
334
330
|
|
|
335
|
-
|
|
336
|
-
|
|
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.
|
|
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
|
|
@@ -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)
|
|
641
|
-
this.container.addClass('auto-apply');
|
|
642
|
-
}
|
|
591
|
+
if (!this.timePicker && this.autoApply)
|
|
592
|
+
this.container.addClass('auto-apply');
|
|
643
593
|
}
|
|
644
594
|
|
|
645
|
-
if ((typeof options.ranges === 'undefined' && !this.singleDatePicker) || this.alwaysShowCalendars)
|
|
646
|
-
this.container.addClass('show-calendar');
|
|
647
|
-
}
|
|
595
|
+
if ((typeof options.ranges === 'undefined' && !this.singleDatePicker) || this.alwaysShowCalendars)
|
|
596
|
+
this.container.addClass('show-calendar');
|
|
648
597
|
|
|
649
598
|
this.container.addClass('opens' + this.opens);
|
|
650
599
|
|
|
@@ -850,19 +799,27 @@
|
|
|
850
799
|
* then `endDate` is shifted and a warning is written to console.
|
|
851
800
|
* @property {boolean} invalidDate=false If `true` then and if `invalidDate` return `true`, then an error is logged to console
|
|
852
801
|
* @property {boolean} invalidTime=false If `true` then and if `invalidTime` return `true`, then an error is logged to console
|
|
853
|
-
* @
|
|
802
|
+
* @property {boolean} writeWarning=true If `true` then a warning is written to console if `startDate` or `endDate` is modified
|
|
803
|
+
* with the exception of rounding due to `timePickerStepSize`.
|
|
804
|
+
|
|
854
805
|
*/
|
|
855
806
|
|
|
856
807
|
/**
|
|
857
|
-
*
|
|
858
|
-
* `minSpan`, `maxSpan`, `invalidDate` and `invalidTime`
|
|
859
|
-
*
|
|
808
|
+
* Validate `startDate` and `endDate` or `range` against `timePickerStepSize`, `minDate`, `maxDate`,
|
|
809
|
+
* `minSpan`, `maxSpan`, `invalidDate` and `invalidTime` and modifies them, if needed.
|
|
810
|
+
* When `startDate` or `endDate` are modified, then a warning is written to console by default.
|
|
811
|
+
* @param {constraintOptions} options - Defines which constraints shall be validated
|
|
860
812
|
* @param {Array} [range] - Used to check prefefined range instead of `startDate` and `endDate` => `[name, startDate, endDate]`
|
|
861
|
-
*
|
|
862
|
-
* @
|
|
863
|
-
* @
|
|
813
|
+
* When set, then function does not modify anything, just returning corrected range.
|
|
814
|
+
* @throws `RangeError` if 'minDate' contradicts to 'minSpan'
|
|
815
|
+
* @returns {Array} - Corrected range as array of `[startDate, endDate, isInvalid]` when range is set, otherwise just `isInvalid` object
|
|
816
|
+
* @example
|
|
817
|
+
* constrainDate({}, [DateTime.fromISO('2025-02-03'), DateTime.fromISO('2025-02-25')]) =>
|
|
818
|
+
* [ DateTime.fromISO('2025-02-05'), DateTime.fromISO('2025-02-20'), { startDate: {modified: true}, endDate: {modified: true} } ]
|
|
819
|
+
* constrainDate({span: false, invalidDate: true, invalidTime: true}) =>
|
|
820
|
+
* { startDate: {modified: true, isInvalidDate: true, isInvalidTime: false}, endDate: {modified: false, isInvalidDate: false, isInvalidTime: true} } ]
|
|
864
821
|
*/
|
|
865
|
-
constrainDate: function ({ minMax = true, span = true, stepSize = true, invalidDate = false, invalidTime = false } = {}, range) {
|
|
822
|
+
constrainDate: function ({ minMax = true, span = true, stepSize = true, invalidDate = false, invalidTime = false, writeWarning = true } = {}, range) {
|
|
866
823
|
const name = range === undefined ? null : range[0];
|
|
867
824
|
const nLog = range === undefined ? '' : ` of range '${name}'`;
|
|
868
825
|
let startDate = range === undefined ? this.startDate : range[1];
|
|
@@ -871,6 +828,12 @@
|
|
|
871
828
|
if (!startDate)
|
|
872
829
|
return;
|
|
873
830
|
|
|
831
|
+
let isInvalid = { startDate: { modified: false } };
|
|
832
|
+
if (invalidDate)
|
|
833
|
+
isInvalid.startDate.isInvalidDate = false;
|
|
834
|
+
if (invalidTime)
|
|
835
|
+
isInvalid.startDate.isInvalidTime = false;
|
|
836
|
+
|
|
874
837
|
if (stepSize && this.timePicker) {
|
|
875
838
|
// Round time to step size
|
|
876
839
|
const secs = this.timePickerStepSize.as('seconds');
|
|
@@ -887,7 +850,9 @@
|
|
|
887
850
|
} else {
|
|
888
851
|
startDate = this.minDate;
|
|
889
852
|
}
|
|
890
|
-
|
|
853
|
+
isInvalid.startDate.modified = true;
|
|
854
|
+
if (writeWarning)
|
|
855
|
+
console.warn(`Set startDate${nLog} to ${this.timePicker ? startDate.toISO({ suppressMilliseconds: true }) : startDate.toISODate()} due to 'minDate'`);
|
|
891
856
|
} else if (this.maxDate && startDate > this.maxDate) {
|
|
892
857
|
if (this.timePicker) {
|
|
893
858
|
while (startDate > this.maxDate)
|
|
@@ -895,7 +860,9 @@
|
|
|
895
860
|
} else {
|
|
896
861
|
startDate = this.maxDate.startOf('day');
|
|
897
862
|
}
|
|
898
|
-
|
|
863
|
+
isInvalid.startDate.modified = true;
|
|
864
|
+
if (writeWarning)
|
|
865
|
+
console.warn(`Set startDate${nLog} to ${this.timePicker ? startDate.toISO({ suppressMilliseconds: true }) : startDate.toISODate()} due to 'maxDate'`);
|
|
899
866
|
}
|
|
900
867
|
}
|
|
901
868
|
|
|
@@ -909,30 +876,42 @@
|
|
|
909
876
|
units.push('ampm');
|
|
910
877
|
}
|
|
911
878
|
|
|
912
|
-
if (invalidDate && this.
|
|
913
|
-
|
|
879
|
+
if (invalidDate && this.isInvalidDate(startDate)) {
|
|
880
|
+
isInvalid.startDate.isInvalidDate = true;
|
|
881
|
+
if (writeWarning)
|
|
882
|
+
console.warn(`The startDate${nLog} ${startDate.toISODate()} is invalid by 'isInvalidDate'`);
|
|
883
|
+
}
|
|
914
884
|
|
|
915
885
|
if (invalidTime && this.timePicker) {
|
|
916
886
|
for (let unit of units) {
|
|
917
887
|
if (this.isInvalidTime(startDate, unit, 'start'))
|
|
918
|
-
|
|
888
|
+
isInvalid.startDate.isInvalidTime = true;
|
|
889
|
+
if (writeWarning)
|
|
890
|
+
console.warn(`The startDate${nLog} ${startDate.toISO({ suppressMilliseconds: true })} ${unit} is invalid by 'isInvalidTime'`);
|
|
919
891
|
}
|
|
920
892
|
}
|
|
921
893
|
|
|
922
|
-
|
|
923
894
|
if (this.singleDatePicker) {
|
|
924
895
|
endDate = startDate;
|
|
925
896
|
if (range === undefined) {
|
|
926
897
|
this.startDate = startDate;
|
|
927
898
|
this.endDate = endDate;
|
|
928
|
-
return
|
|
899
|
+
return isInvalid;
|
|
929
900
|
} else {
|
|
930
|
-
return [startDate, endDate];
|
|
901
|
+
return [startDate, endDate, isInvalid];
|
|
931
902
|
}
|
|
932
903
|
}
|
|
933
904
|
|
|
934
905
|
if (endDate == null)
|
|
935
|
-
return;
|
|
906
|
+
return isInvalid;
|
|
907
|
+
|
|
908
|
+
isInvalid.endDate = { modified: false };
|
|
909
|
+
if (invalidDate)
|
|
910
|
+
isInvalid.endDate.isInvalidDate = false;
|
|
911
|
+
if (invalidTime)
|
|
912
|
+
isInvalid.endDate.isInvalidTime = false;
|
|
913
|
+
|
|
914
|
+
|
|
936
915
|
|
|
937
916
|
if (stepSize && this.timePicker) {
|
|
938
917
|
// Round time to step size
|
|
@@ -950,7 +929,9 @@
|
|
|
950
929
|
} else {
|
|
951
930
|
endDate = this.maxDate.endOf('day');
|
|
952
931
|
}
|
|
953
|
-
|
|
932
|
+
isInvalid.endDate.modified = true;
|
|
933
|
+
if (writeWarning)
|
|
934
|
+
console.warn(`Set endDate${nLog} to ${this.timePicker ? endDate.toISO({ suppressMilliseconds: true }) : endDate.toISODate()} due to 'maxDate'`);
|
|
954
935
|
} else if (this.minDate && endDate < this.minDate) {
|
|
955
936
|
if (this.timePicker) {
|
|
956
937
|
while (endDate < this.minDate)
|
|
@@ -958,7 +939,9 @@
|
|
|
958
939
|
} else {
|
|
959
940
|
endDate = this.minDate;
|
|
960
941
|
}
|
|
961
|
-
|
|
942
|
+
isInvalid.endDate.modified = true;
|
|
943
|
+
if (writeWarning)
|
|
944
|
+
console.warn(`Set endDate${nLog} to ${this.timePicker ? endDate.toISO({ suppressMilliseconds: true }) : endDate.toISODate()} due to 'minDate'`);
|
|
962
945
|
}
|
|
963
946
|
}
|
|
964
947
|
|
|
@@ -973,7 +956,9 @@
|
|
|
973
956
|
} else {
|
|
974
957
|
endDate = maxDate.endOf('day');
|
|
975
958
|
}
|
|
976
|
-
|
|
959
|
+
isInvalid.endDate.modified = true;
|
|
960
|
+
if (writeWarning)
|
|
961
|
+
console.warn(`Set endDate${nLog} to ${this.timePicker ? endDate.toISO({ suppressMilliseconds: true }) : endDate.toISODate()} due to 'maxSpan'`);
|
|
977
962
|
}
|
|
978
963
|
}
|
|
979
964
|
|
|
@@ -990,28 +975,35 @@
|
|
|
990
975
|
} else {
|
|
991
976
|
endDate = minDate.endOf('day');
|
|
992
977
|
}
|
|
993
|
-
|
|
978
|
+
iisInvalid.endDate.modified = true;
|
|
979
|
+
if (writeWarning)
|
|
980
|
+
console.warn(`Set endDate${nLog} to ${this.timePicker ? endDate.toISO({ suppressMilliseconds: true }) : endDate.toISODate()} due to 'minSpan'`);
|
|
994
981
|
}
|
|
995
982
|
}
|
|
996
983
|
}
|
|
997
984
|
}
|
|
998
985
|
|
|
999
|
-
if (invalidDate && this.
|
|
1000
|
-
|
|
986
|
+
if (invalidDate && this.isInvalidDate(endDate)) {
|
|
987
|
+
isInvalid.endDate.isInvalidDate = true;
|
|
988
|
+
if (writeWarning)
|
|
989
|
+
console.warn(`The endDate${nLog} ${endDate.toISODate()} is invalid by 'isInvalidDate'`);
|
|
990
|
+
}
|
|
1001
991
|
|
|
1002
992
|
if (invalidTime && this.timePicker) {
|
|
1003
993
|
for (let unit of units) {
|
|
1004
994
|
if (this.isInvalidTime(endDate, unit, 'end'))
|
|
1005
|
-
|
|
995
|
+
isInvalid.endDate.isInvalidTime = true;
|
|
996
|
+
if (writeWarning)
|
|
997
|
+
console.warn(`The endDate${nLog} ${endDate.toISO({ suppressMilliseconds: true })} ${unit} is invalid by 'isInvalidTime'`);
|
|
1006
998
|
}
|
|
1007
999
|
}
|
|
1008
1000
|
|
|
1009
1001
|
if (range === undefined) {
|
|
1010
1002
|
this.startDate = startDate;
|
|
1011
1003
|
this.endDate = endDate;
|
|
1012
|
-
return
|
|
1004
|
+
return isInvalid;
|
|
1013
1005
|
} else {
|
|
1014
|
-
return [startDate, endDate];
|
|
1006
|
+
return [startDate, endDate, isInvalid];
|
|
1015
1007
|
}
|
|
1016
1008
|
|
|
1017
1009
|
},
|
|
@@ -1139,9 +1131,7 @@
|
|
|
1139
1131
|
second = parseInt(this.container.find('.right .secondselect option:last').val(), 10);
|
|
1140
1132
|
}
|
|
1141
1133
|
}
|
|
1142
|
-
//if (this.leftCalendar.month)
|
|
1143
1134
|
this.leftCalendar.month = this.leftCalendar.month.set({ hour: hour, minute: minute, second: second });
|
|
1144
|
-
//if (this.rightCalendar.month)
|
|
1145
1135
|
this.rightCalendar.month = this.rightCalendar.month.set({ hour: hour, minute: minute, second: second });
|
|
1146
1136
|
}
|
|
1147
1137
|
|
|
@@ -1166,7 +1156,7 @@
|
|
|
1166
1156
|
//
|
|
1167
1157
|
var calendar = side == 'left' ? this.leftCalendar : this.rightCalendar;
|
|
1168
1158
|
if (calendar.month == null && !this.startDate && this.initalMonth)
|
|
1169
|
-
calendar.month = this.initalMonth;
|
|
1159
|
+
calendar.month = this.initalMonth.startOf('month');
|
|
1170
1160
|
|
|
1171
1161
|
const firstDay = calendar.month.startOf('month');
|
|
1172
1162
|
const lastDay = calendar.month.endOf('month').startOf('day');
|
|
@@ -1300,10 +1290,10 @@
|
|
|
1300
1290
|
html += '<tr>';
|
|
1301
1291
|
|
|
1302
1292
|
// add week number
|
|
1303
|
-
if (this.
|
|
1304
|
-
html += '<td class="week">' + calendar[row][0].localWeekNumber + '</td>';
|
|
1305
|
-
else if (this.showISOWeekNumbers)
|
|
1293
|
+
if (this.showISOWeekNumbers)
|
|
1306
1294
|
html += '<td class="week">' + calendar[row][0].weekNumber + '</td>';
|
|
1295
|
+
else if (this.showWeekNumbers)
|
|
1296
|
+
html += '<td class="week">' + calendar[row][0].localWeekNumber + '</td>';
|
|
1307
1297
|
|
|
1308
1298
|
for (var col = 0; col < 7; col++) {
|
|
1309
1299
|
|