[gnome-shell] calendar: Fix showing "Next Week" on Sundays



commit 99c97707acd731581a83149d32c90d3e266c499b
Author: Sebastian Keller <sebastian-keller gmx de>
Date:   Sun Aug 19 17:26:09 2012 +0200

    calendar: Fix showing "Next Week" on Sundays
    
    The original code was assuming that getDay() on a Sunday would
    return 7 rather than 0. This broke the "Next Week" logic
    in several places.
    This commit introduces a dayInWeek variable which takes the following
    values on the according days:
    
    weekstart = 1:
    Mo: 0
    Tu: 1
    We: 2
    Th: 3
    Fr: 4
    Sa: 5
    Su: 6
    
    weekstart = 0:
    Su: 0
    Mo: 1
    Tu: 2
    We: 3
    Th: 4
    Fr: 5
    Sa: 6
    
    Using this we can simplify and fix the conditional that decides
    whether to show "This week" or "Next week" which was broken on
    Sundays.
    
    This commit also fixes the period that gets shown for "Next week"
    on Sundays. Due to the bug it was 13 + 1 - 0 or 13 + 0 - 0 on
    Sundays:
    
    weekStart = 1:
    saturday: saturday + 13 - day_in_week = saturday + 8 = sunday next week
    sunday: sunday + 13 - day_in_week = sunday + 7 = sunday next week
    
    weekStart = 0:
    friday: friday + 13 - day_in_week = friday + 8 = saturday next week
    saturday: saturday + 13 - day_in_week = friday + 7 = saturday next week
    
    https://bugzilla.gnome.org/show_bug.cgi?id=682198

 js/ui/calendar.js |    8 +++++---
 1 files changed, 5 insertions(+), 3 deletions(-)
---
diff --git a/js/ui/calendar.js b/js/ui/calendar.js
index fc01ca5..33e327e 100644
--- a/js/ui/calendar.js
+++ b/js/ui/calendar.js
@@ -717,13 +717,15 @@ const EventsList = new Lang.Class({
         let tomorrowEnd = new Date(dayEnd.getTime() + 86400 * 1000);
         this._addPeriod(_("Tomorrow"), tomorrowBegin, tomorrowEnd, false, true);
 
-        if (dayEnd.getDay() <= 4 + this._weekStart) {
+        let dayInWeek = (dayEnd.getDay() - this._weekStart + 7) % 7;
+
+        if (dayInWeek < 5) {
             /* 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 + this._weekStart - dayEnd.getDay()) * 86400 * 1000);
+            let thisWeekEnd = new Date(dayEnd.getTime() + (6 - dayInWeek) * 86400 * 1000);
             this._addPeriod(_("This week"), thisWeekBegin, thisWeekEnd, true, false);
         } else {
             /* otherwise it's one of the two last days of the week ... show
@@ -731,7 +733,7 @@ const EventsList = new Lang.Class({
              * Saturday/Sunday
              */
             let nextWeekBegin = new Date(dayBegin.getTime() + 2 * 86400 * 1000);
-            let nextWeekEnd = new Date(dayEnd.getTime() + (13 + this._weekStart - dayEnd.getDay()) * 86400 * 1000);
+            let nextWeekEnd = new Date(dayEnd.getTime() + (13 - dayInWeek) * 86400 * 1000);
             this._addPeriod(_("Next week"), nextWeekBegin, nextWeekEnd, true, false);
         }
     },



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