aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--tests/unit/datepicker/datepicker_options.js11
-rw-r--r--ui/ui.datepicker.js3
2 files changed, 13 insertions, 1 deletions
diff --git a/tests/unit/datepicker/datepicker_options.js b/tests/unit/datepicker/datepicker_options.js
index 0a111a93c..768f43c27 100644
--- a/tests/unit/datepicker/datepicker_options.js
+++ b/tests/unit/datepicker/datepicker_options.js
@@ -404,6 +404,17 @@ test('setDate', function() {
equalsDate(inp.datepicker('getDate'), date1, 'Set date - two dates');
inp.datepicker('setDate');
ok(inp.datepicker('getDate') == null, 'Set date - null');
+ // Relative to current date
+ date1 = new Date();
+ date1.setDate(date1.getDate() + 7);
+ inp.datepicker('setDate', 'c +7');
+ equalsDate(inp.datepicker('getDate'), date1, 'Set date - c +7');
+ date1.setDate(date1.getDate() + 7);
+ inp.datepicker('setDate', 'c+7');
+ equalsDate(inp.datepicker('getDate'), date1, 'Set date - c+7');
+ date1.setDate(date1.getDate() - 21);
+ inp.datepicker('setDate', 'c -3 w');
+ equalsDate(inp.datepicker('getDate'), date1, 'Set date - c -3 w');
// Inline
var inl = init('#inl');
date1 = new Date(2008, 6 - 1, 4);
diff --git a/ui/ui.datepicker.js b/ui/ui.datepicker.js
index f82ef3efc..a106ed291 100644
--- a/ui/ui.datepicker.js
+++ b/ui/ui.datepicker.js
@@ -1197,7 +1197,8 @@ $.extend(Datepicker.prototype, {
catch (e) {
// Ignore
}
- var date = new Date();
+ var date = (offset.toLowerCase().match(/^c/) ?
+ $.datepicker._getDate(inst) : null) || new Date();
var year = date.getFullYear();
var month = date.getMonth();
var day = date.getDate();