Skip to content

Commit d82f4f2

Browse files
committed
Date: months method - Clone and then adjust date to avoid formatting issues and fix failing test.
1 parent e6f1047 commit d82f4f2

File tree

2 files changed

+11
-9
lines changed

2 files changed

+11
-9
lines changed

datepicker-rewrite/date.js

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -140,15 +140,16 @@ $.date = function( datestring, formatstring ) {
140140
},
141141
// specialized for multi-month template, could be used in general
142142
months: function( add ) {
143-
var result = [],
144-
current = date.getMonth();
145-
for ( var i = 0; i < add + 1; i++ ) {
146-
result.push( this.clone() );
147-
this.adjust( "M", 1 );
143+
var clone,
144+
result = [ this ];
145+
146+
for ( var i = 0; i < add; i++ ) {
147+
clone = this.clone();
148+
clone.adjust( "M", i + 1 );
149+
result.push( clone );
148150
}
149151
result[ 0 ].first = true;
150152
result[ result.length - 1 ].last = true;
151-
date.setMonth( current );
152153
return result;
153154
},
154155
iso8601Week: function(date) {

datepicker-rewrite/picker.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -292,11 +292,13 @@ $.widget( "ui.datepicker", {
292292
},
293293
_buildMultiplePicker: function() {
294294
var html = "",
295-
// TODO: All months returned by months() are the same?
295+
currentDate = this.date,
296296
months = this.date.months( this.options.numberOfMonths - 1 ),
297297
i = 0;
298298

299299
for ( i; i < months.length; i++ ) {
300+
this.date = months[ i ];
301+
300302
html += "<div class='ui-datepicker-group'>" +
301303
"<div class='ui-datepicker-header ui-widget-header ui-helper-clearfix ui-corner-all'>";
302304
if ( months[i].first ) {
@@ -306,8 +308,6 @@ $.widget( "ui.datepicker", {
306308
html += this._buildNextLink();
307309
}
308310

309-
// TODO: Change _buildTitlebar and _buildGrid to handle for multiple months.
310-
// Right now they just use this.date.
311311
html += this._buildTitlebar();
312312
html += "</div>";
313313
html += this._buildGrid();
@@ -317,6 +317,7 @@ $.widget( "ui.datepicker", {
317317
html += "<div class='ui-datepicker-row-break'></div>";
318318
html += this._buildButtons();
319319

320+
this.date = currentDate;
320321
return html;
321322
},
322323
_buildHeader: function() {

0 commit comments

Comments
 (0)