r2423 - Datepicker: fixed #4285 - Week of the Year off by one during daylight saving time
Author: kbwood.au
Date: Wed Apr 1 03:41:22 2009
New Revision: 2423
Modified:
trunk/ui/ui.datepicker.js
Log:
Datepicker: fixed #4285 - Week of the Year off by one during daylight
saving time
And simplified calculation
Modified: trunk/ui/ui.datepicker.js
==============================================================================
--- trunk/ui/ui.datepicker.js (original)
+++ trunk/ui/ui.datepicker.js Wed Apr 1 03:41:22 2009
@@ -821,20 +821,13 @@
@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.