[gnome-shell/gnome-40] calendar: Start ranges at 0:00 and iterate in whole days



commit 7c5cb402a63baf78f2b6e520f155a79bdf7d73aa
Author: Sebastian Keller <skeller gnome org>
Date:   Thu Nov 4 15:34:45 2021 +0100

    calendar: Start ranges at 0:00 and iterate in whole days
    
    Using a starting time other than 0:00 will prevent events before the
    chosen starting time from showing up for that range. This was causing
    events before 12:00 to be missing in the shell calendar on the first day
    of a range.
    
    Fix this by always starting at 0:00 and then incrementing by days rather
    than a time value that depending on DST or leap seconds may or may not
    correspond to a day.
    
    Part-of: <https://gitlab.gnome.org/GNOME/gnome-shell/-/merge_requests/2023>
    (cherry picked from commit 96047783437a55b5421f3535f9979fdd630b5285)

 js/ui/calendar.js | 13 +++++--------
 1 file changed, 5 insertions(+), 8 deletions(-)
---
diff --git a/js/ui/calendar.js b/js/ui/calendar.js
index 0ff103f2c4..f0d8622666 100644
--- a/js/ui/calendar.js
+++ b/js/ui/calendar.js
@@ -12,7 +12,6 @@ const Util = imports.misc.util;
 
 const { loadInterfaceXML } = imports.misc.fileUtils;
 
-var MSECS_IN_DAY = 24 * 60 * 60 * 1000;
 var SHOW_WEEKDATE_KEY = 'show-weekdate';
 
 var MESSAGE_ICON_SIZE = -1; // pick up from CSS
@@ -498,7 +497,7 @@ var Calendar = GObject.registerClass({
             else
                 col = offsetCols + (7 + iter.getDay() - this._weekStart) % 7;
             layout.attach(label, col, 1, 1, 1);
-            iter.setTime(iter.getTime() + MSECS_IN_DAY);
+            iter.setDate(iter.getDate() + 1);
         }
 
         // All the children after this are days, and get removed when we update the calendar
@@ -599,10 +598,8 @@ var Calendar = GObject.registerClass({
         // Actually computing the number of weeks is complex, but we know that the
         // problematic categories (2 and 4) always start on week start, and that
         // all months at the end have 6 weeks.
-        let beginDate = new Date(this._selectedDate);
-        beginDate.setDate(1);
-        beginDate.setSeconds(0);
-        beginDate.setHours(12);
+        let beginDate = new Date(
+            this._selectedDate.getFullYear(), this._selectedDate.getMonth(), 1);
 
         this._calendarBegin = new Date(beginDate);
         this._markedAsToday = now;
@@ -611,7 +608,7 @@ var Calendar = GObject.registerClass({
         let startsOnWeekStart = daysToWeekStart == 0;
         let weekPadding = startsOnWeekStart ? 7 : 0;
 
-        beginDate.setTime(beginDate.getTime() - (weekPadding + daysToWeekStart) * MSECS_IN_DAY);
+        beginDate.setDate(beginDate.getDate() - (weekPadding + daysToWeekStart));
 
         let layout = this.layout_manager;
         let iter = new Date(beginDate);
@@ -682,7 +679,7 @@ var Calendar = GObject.registerClass({
                 layout.attach(label, rtl ? 7 : 0, row, 1, 1);
             }
 
-            iter.setTime(iter.getTime() + MSECS_IN_DAY);
+            iter.setDate(iter.getDate() + 1);
 
             if (iter.getDay() == this._weekStart)
                 row++;


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