After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 736722 - Calendar in clock applet makes mistake on week number
Calendar in clock applet makes mistake on week number
Status: RESOLVED FIXED
Product: gnome-shell
Classification: Core
Component: calendar
unspecified
Other Linux
: Normal normal
: ---
Assigned To: gnome-shell-maint
gnome-shell-maint
: 742354 745912 747004 747240 (view as bug list)
Depends on:
Blocks:
 
 
Reported: 2014-09-16 07:25 UTC by Issa Gorissen
Modified: 2015-07-01 07:19 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
Patch (1.36 KB, patch)
2014-11-13 11:00 UTC, Alberto Garcia
reviewed Details | Review
calendar: Stop computing week number ourselves (2.18 KB, patch)
2014-11-13 15:25 UTC, Florian Müllner
committed Details | Review

Description Issa Gorissen 2014-09-16 07:25:22 UTC
GNOME version 3.10.2

I've the date and time shown on the top bar. When I click on it, I can see a calendar.

I have enabled the week number on the calendar. And I discovered a mistake in the computation of week number.

Take date March 23rd 2015 and March 30th 2015, they both are on week numbered 13.
Comment 1 Alberts Muktupāvels 2014-09-16 18:09:48 UTC
Are you using session with 2 panels - one at top of screen and one at bottom? Or what is full name of session you are using?

These days GNOME Applets are no longer part of GNOME session. This product/module is only used in unofficial session - GNOME Flashback.
Comment 2 Issa Gorissen 2014-09-18 07:28:05 UTC
Only the default panel on the top of the screen (gnome shell).

Did a ps efww, but could only see this related to calendars

/usr/lib/gnome-shell/gnome-shell-calendar-server

Please note I have activated the week numbers of the Clock/Calendar via

- Tweak Tool/Top Bar
Comment 3 Issa Gorissen 2014-09-18 07:29:21 UTC
Only the default panel on the top of the screen (gnome shell).

Did a ps efww, but could only see this related to calendars

/usr/lib/gnome-shell/gnome-shell-calendar-server

Please note I have activated the week numbers of the Clock/Calendar via

- Tweak Tool/Top Bar
Comment 4 Alberts Muktupāvels 2014-09-18 09:04:13 UTC
Thanks for info!
Comment 5 Florian Müllner 2014-09-18 10:05:44 UTC
Indeed, I can reproduce this here.
Comment 6 Alberto Garcia 2014-11-11 13:20:09 UTC
Also with gnome 3.14.1.

Week 43 (October 2015) is missing. I think this coincides with the daylight saving time changes in both cases, so most likely the algorithm used to compute the week number is not taking that into account.
Comment 7 Alberto Garcia 2014-11-13 11:00:47 UTC
Created attachment 290625 [details] [review]
Patch

So the algorithm works like this: week #1 is the one that contains the
1st Thursday. In order to get the current week number, we follow these
steps:

- Get the date from the current week's Thursday (at midnight)
- Get the date from January the 1st.
- See how many days passed from January the 1st to this week's Thursday.
- Divide by 7 and add 1.

Now, in order to see how many days passed the algorithm calculates the
difference (in msecs) and does Math.floor(Math.abs(diffDate) / MSECS_IN_DAY).

The problem is that not all days are MSECS_IN_DAY long. During
daylight saving time there's one hour missing, so for example the 2nd
of April of 2015 is 91 days after January the 1st, but the result of
our operation is 90.9583. Since we are rounding downwards, one day is
lost. The problem remains until autumn, when there's one day that's
one hour longer, that's why there's w43 missing in 2015.

Replacing Math.floor() with Math.round() should be enough. As I
explained above, diffDate is either a multiple of MSECS_IN_DAY or
there's a difference of one hour, so we can safely round the result of
the division to the nearest integer.
Comment 8 Florian Müllner 2014-11-13 15:24:49 UTC
Review of attachment 290625 [details] [review]:

::: js/ui/calendar.js
@@ +101,3 @@
     let diffDate = nearestThursday - jan1st;
+    // Round to nearest integer since days aren't always equally long (due to DST)
+    let dayNumber = Math.round(Math.abs(diffDate) / MSECS_IN_DAY);

This is probably right, but I wonder if it makes sense to throw out the error-prone code altogether. I'll attach a proposal to do that.
Comment 9 Florian Müllner 2014-11-13 15:25:26 UTC
Created attachment 290644 [details] [review]
calendar: Stop computing week number ourselves

Correctly computing the ISO week number is tricky and we already
have code in the platform to do it, so just refer its computation
to GDateTime rather than doing it ourselves.
Comment 10 Alberto Garcia 2014-11-13 15:32:30 UTC
-   let label = new St.Label({ text: _getCalendarWeekForDate(iter).toString(),
+   let label = new St.Label({ text: iter.toLocaleFormat('%V'),

Yes, that's certainly much better.

I wasn't aware of that method. I wonder why this was not used from the
beginning though...
Comment 11 Florian Müllner 2014-11-27 14:10:36 UTC
Attachment 290644 [details] pushed as 1e8e5d4 - calendar: Stop computing week number ourselves
Comment 12 Florian Müllner 2015-01-05 21:01:55 UTC
*** Bug 742354 has been marked as a duplicate of this bug. ***
Comment 13 Olivier Crête 2015-03-02 20:08:02 UTC
Sorry for spamming this bug, but any chance we can get an update into F21 for this?
Comment 14 Florian Müllner 2015-03-02 20:10:36 UTC
(In reply to Olivier Crête from comment #13)
> Sorry for spamming this bug, but any chance we can get an update into F21
> for this?

Yes, if you can find a Fedora packager who is not busy resolving blocker bugs for 3.16 ...
Comment 15 Kevin Woldt 2015-03-06 13:49:56 UTC
Bug confirmed with 3.14.2
week 13 at March 23rd 30th
week 43 missing
Comment 16 Florian Müllner 2015-03-10 14:24:55 UTC
*** Bug 745912 has been marked as a duplicate of this bug. ***
Comment 17 Rui Matos 2015-03-30 09:32:25 UTC
*** Bug 747004 has been marked as a duplicate of this bug. ***
Comment 18 Rui Matos 2015-04-02 13:25:47 UTC
*** Bug 747240 has been marked as a duplicate of this bug. ***