Allow relative dates with multiple periods

This commit is contained in:
Keith Wood 2008-06-16 09:56:43 +00:00
parent 74b7cde939
commit 837699c7e0
2 changed files with 10 additions and 8 deletions

View File

@ -204,7 +204,8 @@
options: [
{ desc: 'January 1, 2007', source: '$("#defaultDate").datepicker({defaultDate: new Date(2007, 1 - 1, 1), showOn: "both", buttonImage: "templates/images/calendar.gif", buttonImageOnly: true});' },
{ desc: '7 days from today', source: '$("#defaultDate").datepicker({defaultDate: +7, showOn: "both", buttonImage: "templates/images/calendar.gif", buttonImageOnly: true});' },
{ desc: '2 weeks from today', source: '$("#defaultDate").datepicker({defaultDate: "+2w", showOn: "both", buttonImage: "templates/images/calendar.gif", buttonImageOnly: true});' }
{ desc: '2 weeks from today', source: '$("#defaultDate").datepicker({defaultDate: "+2w", showOn: "both", buttonImage: "templates/images/calendar.gif", buttonImageOnly: true});' },
{ desc: '10 days and 1 month from today', source: '$("#defaultDate").datepicker({defaultDate: "+10 D +1 M", showOn: "both", buttonImage: "templates/images/calendar.gif", buttonImageOnly: true});' }
]
},

View File

@ -1054,11 +1054,12 @@ $.extend(DatepickerInstance.prototype, {
};
var offsetString = function(offset, getDaysInMonth) {
var date = new Date();
var matches = /^([+-]?[0-9]+)\s*(d|D|w|W|m|M|y|Y)?$/.exec(offset);
if (matches) {
var year = date.getFullYear();
var month = date.getMonth();
var day = date.getDate();
var year = date.getFullYear();
var month = date.getMonth();
var day = date.getDate();
var pattern = /([+-]?[0-9]+)\s*(d|D|w|W|m|M|y|Y)?/g;
var matches = pattern.exec(offset);
while (matches) {
switch (matches[2] || 'd') {
case 'd' : case 'D' :
day += (matches[1] - 0); break;
@ -1073,9 +1074,9 @@ $.extend(DatepickerInstance.prototype, {
day = Math.min(day, getDaysInMonth(year, month));
break;
}
date = new Date(year, month, day);
matches = pattern.exec(offset);
}
return date;
return new Date(year, month, day);
};
var date = this._get(name);
return (date == null ? defaultDate :