r2955 commited - Datepicker: Fixed #4647 setDate cannot be called multiple times

r2955 commited - Datepicker: Fixed #4647 setDate cannot be called multiple times


Revision: 2955
Author: kbwood.au
Date: Wed Jul 22 01:28:01 2009
Log: Datepicker: Fixed #4647 setDate cannot be called multiple times
http://code.google.com/p/jquery-ui/source/detail?r=2955
Modified:
/trunk/tests/unit/datepicker/datepicker_options.js
/trunk/ui/ui.datepicker.js
=======================================
--- /trunk/tests/unit/datepicker/datepicker_options.js    Sun Jun 21 00:28:51
2009
+++ /trunk/tests/unit/datepicker/datepicker_options.js    Wed Jul 22 01:28:01
2009
@@ -404,6 +404,17 @@
    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);
=======================================
--- /trunk/ui/ui.datepicker.js    Sat Jul 4 22:26:14 2009
+++ /trunk/ui/ui.datepicker.js    Wed Jul 22 01:28:01 2009
@@ -1197,7 +1197,8 @@
            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();