inp.val('').datepicker('show').
simulate('keydown', {keyCode: $.simulate.VK_ENTER});
equalsDate(inp.datepicker('getDate'), date, 'Default date null');
- // numeric values
+ // Numeric values
inp.datepicker('option', {defaultDate: -2}).
datepicker('hide').val('').datepicker('show').
simulate('keydown', {keyCode: $.simulate.VK_ENTER});
datepicker('hide').val('').datepicker('show').
simulate('keydown', {keyCode: $.simulate.VK_ENTER});
equalsDate(inp.datepicker('getDate'), date, 'Default date NaN');
- // string values
+ // String offset values
inp.datepicker('option', {defaultDate: '-1d'}).
datepicker('hide').val('').datepicker('show').
simulate('keydown', {keyCode: $.simulate.VK_ENTER});
date = addMonths(new Date(), 1);
date.setDate(date.getDate() + 10);
equalsDate(inp.datepicker('getDate'), date, 'Default date +1M +10d');
+ // String date values
+ inp.datepicker('option', {defaultDate: '07/04/2007'}).
+ datepicker('hide').val('').datepicker('show').
+ simulate('keydown', {keyCode: $.simulate.VK_ENTER});
+ date = new Date(2007, 7 - 1, 4);
+ equalsDate(inp.datepicker('getDate'), date, 'Default date 07/04/2007');
+ inp.datepicker('option', {dateFormat: 'yy-mm-dd', defaultDate: '2007-04-02'}).
+ datepicker('hide').val('').datepicker('show').
+ simulate('keydown', {keyCode: $.simulate.VK_ENTER});
+ date = new Date(2007, 4 - 1, 2);
+ equalsDate(inp.datepicker('getDate'), date, 'Default date 2007-04-02');
+ // Date value
date = new Date(2007, 1 - 1, 26);
- inp.datepicker('option', {defaultDate: date}).
+ inp.datepicker('option', {dateFormat: 'mm/dd/yy', defaultDate: date}).
datepicker('hide').val('').datepicker('show').
simulate('keydown', {keyCode: $.simulate.VK_ENTER});
equalsDate(inp.datepicker('getDate'), date, 'Default date 01/26/2007');
/* Retrieve the default date shown on opening. */
_getDefaultDate: function(inst) {
return this._restrictMinMax(inst,
- this._determineDate(this._get(inst, 'defaultDate'), new Date()));
+ this._determineDate(inst, this._get(inst, 'defaultDate'), new Date()));
},
/* A date may be specified as an exact value or a relative one. */
- _determineDate: function(date, defaultDate) {
+ _determineDate: function(inst, date, defaultDate) {
var offsetNumeric = function(offset) {
var date = new Date();
date.setDate(date.getDate() + offset);
return date;
};
- var offsetString = function(offset, getDaysInMonth) {
+ var offsetString = function(offset) {
+ try {
+ return $.datepicker.parseDate($.datepicker._get(inst, 'dateFormat'),
+ offset, $.datepicker._getFormatConfig(inst));
+ }
+ catch (e) {
+ // Ignore
+ }
var date = new Date();
var year = date.getFullYear();
var month = date.getMonth();
day += parseInt(matches[1],10) * 7; break;
case 'm' : case 'M' :
month += parseInt(matches[1],10);
- day = Math.min(day, getDaysInMonth(year, month));
+ day = Math.min(day, $.datepicker._getDaysInMonth(year, month));
break;
case 'y': case 'Y' :
year += parseInt(matches[1],10);
- day = Math.min(day, getDaysInMonth(year, month));
+ day = Math.min(day, $.datepicker._getDaysInMonth(year, month));
break;
}
matches = pattern.exec(offset);
}
return new Date(year, month, day);
};
- date = (date == null ? defaultDate :
- (typeof date == 'string' ? offsetString(date, this._getDaysInMonth) :
+ date = (date == null ? defaultDate : (typeof date == 'string' ? offsetString(date) :
(typeof date == 'number' ? (isNaN(date) ? defaultDate : offsetNumeric(date)) : date)));
date = (date && date.toString() == 'Invalid Date' ? defaultDate : date);
if (date) {
var clear = !(date);
var origMonth = inst.selectedMonth;
var origYear = inst.selectedYear;
- date = this._restrictMinMax(inst, this._determineDate(date, new Date()));
+ date = this._restrictMinMax(inst, this._determineDate(inst, date, new Date()));
inst.selectedDay = inst.currentDay = date.getDate();
inst.drawMonth = inst.selectedMonth = inst.currentMonth = date.getMonth();
inst.drawYear = inst.selectedYear = inst.currentYear = date.getFullYear();
/* Determine the current maximum date - ensure no time components are set. */
_getMinMaxDate: function(inst, minMax) {
- return this._determineDate(this._get(inst, minMax + 'Date'), null);
+ return this._determineDate(inst, this._get(inst, minMax + 'Date'), null);
},
/* Find the number of days in a given month. */