Skip to content

Commit 55ff628

Browse files
committed
Add multidate set/get methods to handle multiple date inputs.
Closes uxsolutions#724
1 parent 1c3a818 commit 55ff628

File tree

2 files changed

+57
-5
lines changed

2 files changed

+57
-5
lines changed

docs/methods.rst

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,26 @@ Arguments:
6868
Sets the internal date. ``date`` is assumed to be a UTC date object, and will not be converted.
6969

7070

71+
setDates
72+
--------
73+
74+
Arguments:
75+
76+
* date[, date[, ...]] (Date)
77+
78+
Sets the internal date list. Each ``date`` is assumed to be a "local" date object, and will be converted to UTC for internal use. For use with multidate pickers.
79+
80+
81+
setUTCDates
82+
-----------
83+
84+
Arguments:
85+
86+
* date[, date[, ...]] (Date)
87+
88+
Sets the internal date list. Each ``date`` is assumed to be a UTC date object, and will not be converted. For use with multidate pickers.
89+
90+
7191
getDate
7292
-------
7393

@@ -84,6 +104,22 @@ Arguments: None
84104
Returns the internal UTC date object, as-is and unconverted to local time, of the first datepicker in the selection. For multidate pickers, returns the latest date selected.
85105

86106

107+
getDates
108+
--------
109+
110+
Arguments: None
111+
112+
Returns a list of localized date objects representing the internal date objects of the first datepicker in the selection. For use with multidate pickers.
113+
114+
115+
getUTCDates
116+
-----------
117+
118+
Arguments: None
119+
120+
Returns the internal list of UTC date objects, as they are and unconverted to local time, of the first datepicker in the selection. For use with multidate pickers.
121+
122+
87123
setStartDate
88124
------------
89125

js/bootstrap-datepicker.js

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,11 @@
3131
var today = new Date();
3232
return UTCDate(today.getFullYear(), today.getMonth(), today.getDate());
3333
}
34+
function alias(method){
35+
return function(){
36+
this[method].apply(this, arguments);
37+
}
38+
}
3439

3540
var DateArray = (function(){
3641
var extras = {
@@ -453,24 +458,35 @@
453458
return utc && new Date(Date.UTC(utc.getUTCFullYear(), utc.getUTCMonth(), utc.getUTCDate()));
454459
},
455460

461+
getDates: function(){
462+
return $.map(this.dates, this._utc_to_local);
463+
},
464+
465+
getUTCDates: function(){
466+
return $.map(this.dates, function(d){ return new Date(d); });
467+
},
468+
456469
getDate: function() {
457470
return this._utc_to_local(this.getUTCDate());
458471
},
459472

460473
getUTCDate: function() {
461-
return this.dates.get(-1);
474+
return new Date(this.dates.get(-1));
462475
},
463476

464-
setDate: function(d) {
465-
this.update(d);
477+
setDates: function() {
478+
this.update.apply(this, arguments);
466479
this.setValue();
467480
},
468481

469-
setUTCDate: function(d) {
470-
this.update(this._utc_to_local(d));
482+
setUTCDates: function() {
483+
this.update.apply(this, $.map(arguments, this._utc_to_local));
471484
this.setValue();
472485
},
473486

487+
setDate: alias('setDates'),
488+
setUTCDate: alias('setUTCDates'),
489+
474490
setValue: function() {
475491
var formatted = this.getFormattedDate();
476492
if (!this.isInput) {

0 commit comments

Comments
 (0)