plugins/calendar

Thomas Brüderli bruederli at kolabsys.com
Wed Jul 4 18:01:02 CEST 2012


 plugins/calendar/calendar_ui.js |   17 ++++++++++++-----
 1 file changed, 12 insertions(+), 5 deletions(-)

New commits:
commit 95f17173c4d6414f934c5fe750850ba2846ce0f5
Author: Thomas Bruederli <bruederli at kolabsys.com>
Date:   Wed Jul 4 18:00:55 2012 +0200

    Workaround for wrong week of the year display when first day of week is not Monday (#866)

diff --git a/plugins/calendar/calendar_ui.js b/plugins/calendar/calendar_ui.js
index 5d84b1b..8e84abc 100644
--- a/plugins/calendar/calendar_ui.js
+++ b/plugins/calendar/calendar_ui.js
@@ -2492,6 +2492,13 @@ function rcube_calendar_ui(settings)
       event_times_changed();
     };
 
+    // Set as calculateWeek to determine the week of the year based on the ISO 8601 definition.
+    // Uses the default $.datepicker.iso8601Week() function but takes firstDay setting into account.
+    // This is a temporary fix until http://bugs.jqueryui.com/ticket/8420 is resolved.
+    var iso8601Week = datepicker_settings.calculateWeek = function(date) {
+      var mondayOffset = Math.abs(1 - datepicker_settings.firstDay);
+      return $.datepicker.iso8601Week(new Date(date.getTime() + mondayOffset * 86400000));
+    };
 
     var minical;
     var init_calendar_ui = function()
@@ -2525,11 +2532,11 @@ function rcube_calendar_ui(settings)
             if (minical.data('year'))
               base_date.setYear(minical.data('year'));
             base_date.setHours(12);
-            var day_off = base_date.getDay() - 1;
-            if (day_off < 0) day_off = 6;
-            var base_kw = $.datepicker.iso8601Week(base_date);
-            var kw = parseInt(cell.html());
-            var diff = (kw - base_kw) * 7 * DAY_MS;
+            base_date.setDate(base_date.getDate() - ((base_date.getDay() + 6) % 7) + datepicker_settings.firstDay);
+            var day_off = base_date.getDay() - datepicker_settings.firstDay;
+            var base_kw = iso8601Week(base_date);
+            var target_kw = parseInt(cell.html());
+            var diff = (target_kw - base_kw) * 7 * DAY_MS;
             // select monday of the chosen calendar week
             var date = new Date(base_date.getTime() - day_off * DAY_MS + diff);
             fc.fullCalendar('gotoDate', date).fullCalendar('setDate', date).fullCalendar('changeView', 'agendaWeek');





More information about the commits mailing list