[gnome-shell] calendar: Fix event list for week starts other than Sunday



commit d6749589e8c960266f434cb12f5709fa0fbf99ad
Author: Florian Müllner <fmuellner gnome org>
Date:   Sat Jan 29 03:09:47 2011 +0100

    calendar: Fix event list for week starts other than Sunday
    
    In non-US locales, Monday is generally considered the first day
    of the week. Take this into account when building the event
    lists displayed under "This week"/"Next week".
    
    https://bugzilla.gnome.org/show_bug.cgi?id=641049
    
    Signed-off-by: David Zeuthen <davidz redhat com>

 js/ui/calendar.js |   28 +++++++++++++++++++++-------
 1 files changed, 21 insertions(+), 7 deletions(-)
---
diff --git a/js/ui/calendar.js b/js/ui/calendar.js
index 07b9d29..dcea566 100644
--- a/js/ui/calendar.js
+++ b/js/ui/calendar.js
@@ -633,6 +633,18 @@ EventsList.prototype = {
         this._eventSource.connect('changed', Lang.bind(this, this._update));
         this._desktopSettings = new Gio.Settings({ schema: 'org.gnome.desktop.interface' });
         this._desktopSettings.connect('changed', Lang.bind(this, this._update));
+        let weekStartString = Gettext_gtk30.gettext('calendar:week_start:0');
+        if (weekStartString.indexOf('calendar:week_start:') == 0) {
+            this._weekStart = parseInt(weekStartString.substring(20));
+        }
+
+        if (isNaN(this._weekStart) ||
+                  this._weekStart < 0 ||
+                  this._weekStart > 6) {
+            log('Translation of "calendar:week_start:0" in GTK+ is not correct');
+            this._weekStart = 0;
+        }
+
         this._update();
     },
 
@@ -714,19 +726,21 @@ EventsList.prototype = {
         let tomorrowEnd = new Date(dayEnd.getTime() + 86400 * 1000);
         this._addPeriod(_("Tomorrow"), tomorrowBegin, tomorrowEnd, false, true);
 
-        if (dayEnd.getDay() <= 4) {
-            /* if now is Sunday through Thursday show "This week" and include events up until
-             * and including Saturday
+        if (dayEnd.getDay() <= 4 + this._weekStart) {
+            /* If now is within the first 5 days we show "This week" and
+             * include events up until and including Saturday/Sunday
+             * (depending on whether a week starts on Sunday/Monday).
              */
             let thisWeekBegin = new Date(dayBegin.getTime() + 2 * 86400 * 1000);
-            let thisWeekEnd = new Date(dayEnd.getTime() + (6 - dayEnd.getDay()) * 86400 * 1000);
+            let thisWeekEnd = new Date(dayEnd.getTime() + (6 + this._weekStart - dayEnd.getDay()) * 86400 * 1000);
             this._addPeriod(_("This week"), thisWeekBegin, thisWeekEnd, true, false);
         } else {
-            /* otherwise it's a Friday or Saturday... show "Next week" and include events up
-             * until and including *next* Saturday
+            /* otherwise it's one of the two last days of the week ... show
+             * "Next week" and include events up until and including *next*
+             * Saturday/Sunday
              */
             let nextWeekBegin = new Date(dayBegin.getTime() + 2 * 86400 * 1000);
-            let nextWeekEnd = new Date(dayEnd.getTime() + (13 - dayEnd.getDay()) * 86400 * 1000);
+            let nextWeekEnd = new Date(dayEnd.getTime() + (13 + this._weekStart - dayEnd.getDay()) * 86400 * 1000);
             this._addPeriod(_("Next week"), nextWeekBegin, nextWeekEnd, true, false);
         }
     },



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]