diff --git a/demos/functional/templates/ui.datepicker.html b/demos/functional/templates/ui.datepicker.html index ae4c78fba..453c784ae 100644 --- a/demos/functional/templates/ui.datepicker.html +++ b/demos/functional/templates/ui.datepicker.html @@ -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});' } ] }, diff --git a/ui/ui.datepicker.js b/ui/ui.datepicker.js index 1a1dc1187..643f6de04 100644 --- a/ui/ui.datepicker.js +++ b/ui/ui.datepicker.js @@ -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 :