Skip to content

Commit

Permalink
Calendar bug fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
allenrabinovich committed Feb 29, 2012
1 parent 829f44d commit ecb0e3c
Show file tree
Hide file tree
Showing 9 changed files with 49 additions and 31 deletions.
10 changes: 9 additions & 1 deletion build/calendar-base/calendar-base-debug.js
Original file line number Diff line number Diff line change
Expand Up @@ -817,7 +817,12 @@ Y.CalendarBase = Y.extend( CalendarBase, Y.Widget, {
* set to noon.
*/
_normalizeDate : function (date) {
return new Date(date.getFullYear(), date.getMonth(), 1, 12, 0, 0, 0);
if (date != null) {
return new Date(date.getFullYear(), date.getMonth(), 1, 12, 0, 0, 0);
}
else {
return null;
}
},


Expand Down Expand Up @@ -1574,6 +1579,9 @@ Y.CalendarBase = Y.extend( CalendarBase, Y.Widget, {
if (ydate.areEqual(newDate, this.get('date'))) {
return this.get('date');
}
else {
return newDate;
}
}
},

Expand Down
4 changes: 2 additions & 2 deletions build/calendar-base/calendar-base-min.js

Large diffs are not rendered by default.

10 changes: 9 additions & 1 deletion build/calendar-base/calendar-base.js
Original file line number Diff line number Diff line change
Expand Up @@ -817,7 +817,12 @@ Y.CalendarBase = Y.extend( CalendarBase, Y.Widget, {
* set to noon.
*/
_normalizeDate : function (date) {
return new Date(date.getFullYear(), date.getMonth(), 1, 12, 0, 0, 0);
if (date != null) {
return new Date(date.getFullYear(), date.getMonth(), 1, 12, 0, 0, 0);
}
else {
return null;
}
},


Expand Down Expand Up @@ -1574,6 +1579,9 @@ Y.CalendarBase = Y.extend( CalendarBase, Y.Widget, {
if (ydate.areEqual(newDate, this.get('date'))) {
return this.get('date');
}
else {
return newDate;
}
}
},

Expand Down
9 changes: 4 additions & 5 deletions build/calendar/calendar-debug.js
Original file line number Diff line number Diff line change
Expand Up @@ -433,10 +433,9 @@ Y.Calendar = Y.extend(Calendar, Y.CalendarBase, {
setter: function (val) {

var newDate = this._normalizeDate(val),
newTopDate = ydate.addMonths(newDate, this._paneNumber - 1),
minDate = this.get("minimumDate"),
maxDate = this.get("maximumDate");

newTopDate = ydate.addMonths(newDate, this._paneNumber - 1);
var minDate = this.get("minimumDate");
var maxDate = this.get("maximumDate");
if ((minDate == null || ydate.isGreaterOrEqual(newDate, minDate)) &&
(maxDate == null || ydate.isGreaterOrEqual(maxDate, newTopDate))) {
return newDate;
Expand Down Expand Up @@ -500,7 +499,7 @@ Y.Calendar = Y.extend(Calendar, Y.CalendarBase, {
return newMaxDate;
}
else {
return this._normalizeDate(val);
return val;
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion build/calendar/calendar-min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 4 additions & 5 deletions build/calendar/calendar.js
Original file line number Diff line number Diff line change
Expand Up @@ -433,10 +433,9 @@ Y.Calendar = Y.extend(Calendar, Y.CalendarBase, {
setter: function (val) {

var newDate = this._normalizeDate(val),
newTopDate = ydate.addMonths(newDate, this._paneNumber - 1),
minDate = this.get("minimumDate"),
maxDate = this.get("maximumDate");

newTopDate = ydate.addMonths(newDate, this._paneNumber - 1);
var minDate = this.get("minimumDate");
var maxDate = this.get("maximumDate");
if ((minDate == null || ydate.isGreaterOrEqual(newDate, minDate)) &&
(maxDate == null || ydate.isGreaterOrEqual(maxDate, newTopDate))) {
return newDate;
Expand Down Expand Up @@ -500,7 +499,7 @@ Y.Calendar = Y.extend(Calendar, Y.CalendarBase, {
return newMaxDate;
}
else {
return this._normalizeDate(val);
return val;
}
}
}
Expand Down
10 changes: 9 additions & 1 deletion src/calendar/js/calendar-base.js
Original file line number Diff line number Diff line change
Expand Up @@ -815,7 +815,12 @@ Y.CalendarBase = Y.extend( CalendarBase, Y.Widget, {
* set to noon.
*/
_normalizeDate : function (date) {
return new Date(date.getFullYear(), date.getMonth(), 1, 12, 0, 0, 0);
if (date != null) {
return new Date(date.getFullYear(), date.getMonth(), 1, 12, 0, 0, 0);
}
else {
return null;
}
},


Expand Down Expand Up @@ -1572,6 +1577,9 @@ Y.CalendarBase = Y.extend( CalendarBase, Y.Widget, {
if (ydate.areEqual(newDate, this.get('date'))) {
return this.get('date');
}
else {
return newDate;
}
}
},

Expand Down
9 changes: 4 additions & 5 deletions src/calendar/js/calendar.js
Original file line number Diff line number Diff line change
Expand Up @@ -431,10 +431,9 @@ Y.Calendar = Y.extend(Calendar, Y.CalendarBase, {
setter: function (val) {

var newDate = this._normalizeDate(val),
newTopDate = ydate.addMonths(newDate, this._paneNumber - 1),
minDate = this.get("minimumDate"),
maxDate = this.get("maximumDate");

newTopDate = ydate.addMonths(newDate, this._paneNumber - 1);
var minDate = this.get("minimumDate");
var maxDate = this.get("maximumDate");
if ((minDate == null || ydate.isGreaterOrEqual(newDate, minDate)) &&
(maxDate == null || ydate.isGreaterOrEqual(maxDate, newTopDate))) {
return newDate;
Expand Down Expand Up @@ -498,7 +497,7 @@ Y.Calendar = Y.extend(Calendar, Y.CalendarBase, {
return newMaxDate;
}
else {
return this._normalizeDate(val);
return val;
}
}
}
Expand Down
17 changes: 7 additions & 10 deletions src/calendar/tests/calendar.html
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ <h1>Calendar Tests</h1>
},

tearDown : function () {
delete this.firstcalendar;
delete this.secondcalendar;
delete this.firstcalendar;
delete this.secondcalendar;
Y.one('#firstcontainer').remove();
Y.one('#secondcontainer').remove();
},
Expand Down Expand Up @@ -110,7 +110,6 @@ <h1>Calendar Tests</h1>
Y.Assert.areEqual("7", Y.one("#firstcontainer").one(".calendar_col8.yui3-calendar-nextmonth-day").getContent());
},


testTwoCalendars : function () {
var cfg1 = {
contentBox: "#firstcontainer",
Expand Down Expand Up @@ -150,8 +149,7 @@ <h1>Calendar Tests</h1>
var calendarid = this.firstcalendar._calendarId;
Y.one("#" + calendarid + "_pane_0_6_15").simulate("click");

var currentDate = this.firstcalendar.get("selectedDates")[0];

var currentDate = this.firstcalendar.get("selectedDates")[0];
Y.Assert.areEqual(currentDate.getFullYear(), 2011);
Y.Assert.areEqual(currentDate.getMonth(), 11);
Y.Assert.areEqual(currentDate.getDate(), 15);
Expand All @@ -161,21 +159,20 @@ <h1>Calendar Tests</h1>
Y.one("#" + calendarid + "_pane_0_8_31").simulate("click");

currentDate = this.firstcalendar.get("selectedDates")[0];

Y.Assert.areEqual(currentDate.getFullYear(), 2011);
Y.Assert.areEqual(currentDate.getMonth(), 11);
Y.Assert.areEqual(currentDate.getDate(), 31);

// Click to advance the month
Y.one(".yui3-calendarnav-nextmonth").simulate("click");
Y.one(".yui3-calendarnav-nextmonth").simulate("click");
// Click on a date in the new month
Y.one("#" + calendarid + "_pane_0_8_17").simulate("click");

currentDate = this.firstcalendar.get("selectedDates")[0];

currentDate = this.firstcalendar.get("selectedDates")[0];
Y.Assert.areEqual(currentDate.getFullYear(), 2012);
Y.Assert.areEqual(currentDate.getMonth(), 0);
Y.Assert.areEqual(currentDate.getDate(), 17);

},

testMultiplePanes : function () {
Expand Down

0 comments on commit ecb0e3c

Please sign in to comment.