diff options
author | Keith Wood <kbwood.au@gmail.com> | 2009-04-01 10:41:22 +0000 |
---|---|---|
committer | Keith Wood <kbwood.au@gmail.com> | 2009-04-01 10:41:22 +0000 |
commit | e55ee9e6e9977df6be4d8b9503a5c9756bcbdbd3 (patch) | |
tree | 448b6ae179957d50017b90365f510977b552f1c1 /ui | |
parent | 126210026b6b35b24d216d520294f9fe5753d02c (diff) | |
download | jquery-ui-e55ee9e6e9977df6be4d8b9503a5c9756bcbdbd3.tar.gz jquery-ui-e55ee9e6e9977df6be4d8b9503a5c9756bcbdbd3.zip |
Datepicker: fixed #4285 - Week of the Year off by one during daylight saving time
And simplified calculation
Diffstat (limited to 'ui')
-rw-r--r-- | ui/ui.datepicker.js | 21 |
1 files changed, 7 insertions, 14 deletions
diff --git a/ui/ui.datepicker.js b/ui/ui.datepicker.js index bc5b5cc13..05418b498 100644 --- a/ui/ui.datepicker.js +++ b/ui/ui.datepicker.js @@ -821,20 +821,13 @@ $.extend(Datepicker.prototype, { @param date Date - the date to get the week for @return number - the number of the week within the year that contains this date */ iso8601Week: function(date) { - var checkDate = new Date(date.getFullYear(), date.getMonth(), date.getDate()); - var firstMon = new Date(checkDate.getFullYear(), 1 - 1, 4); // First week always contains 4 Jan - var firstDay = firstMon.getDay() || 7; // Day of week: Mon = 1, ..., Sun = 7 - firstMon.setDate(firstMon.getDate() + 1 - firstDay); // Preceding Monday - if (firstDay < 4 && checkDate < firstMon) { // Adjust first three days in year if necessary - checkDate.setDate(checkDate.getDate() - 3); // Generate for previous year - return $.datepicker.iso8601Week(checkDate); - } else if (checkDate > new Date(checkDate.getFullYear(), 12 - 1, 28)) { // Check last three days in year - firstDay = new Date(checkDate.getFullYear() + 1, 1 - 1, 4).getDay() || 7; - if (firstDay > 4 && (checkDate.getDay() || 7) < firstDay - 3) { // Adjust if necessary - return 1; - } - } - return Math.floor(((checkDate - firstMon) / 86400000) / 7) + 1; // Weeks to given date + var checkDate = new Date(date.getTime()); + // Find Thursday of this week starting on Monday + checkDate.setDate(checkDate.getDate() + 4 - (checkDate.getDay() || 7)); + var time = checkDate.getTime(); + checkDate.setMonth(0); // Compare with Jan 1 + checkDate.setDate(1); + return Math.floor(Math.round((time - checkDate) / 86400000) / 7) + 1; }, /* Parse a string value into a date object. |