Skip to content
Permalink
Browse files

Allow relative dates with multiple periods

  • Loading branch information
Keith Wood
Keith Wood committed Jun 16, 2008
1 parent 74b7cde commit 837699c7e0d2d444a17a2357aafe8d9649eb4987
Showing with 10 additions and 8 deletions.
  1. +2 −1 demos/functional/templates/ui.datepicker.html
  2. +8 −7 ui/ui.datepicker.js
@@ -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});' }
]
},

@@ -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 :

0 comments on commit 837699c

Please sign in to comment.
You can’t perform that action at this time.