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 757622 - Week numbering in year view is incorrect
Week numbering in year view is incorrect
Status: RESOLVED FIXED
Product: gnome-calendar
Classification: Applications
Component: Views
3.18.x
Other Linux
: Normal normal
: 3.26
Assigned To: GNOME Calendar maintainers
GNOME Calendar maintainers
Depends on:
Blocks:
 
 
Reported: 2015-11-05 08:17 UTC by Marcus Lundblad
Modified: 2017-04-17 18:20 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
gnome-calendar: Fix week #s in year view (4.11 KB, patch)
2016-01-19 03:38 UTC, Isaque Galdino
none Details | Review
gnome-calendar: Fix week #s in year view (2.99 KB, patch)
2016-01-19 17:33 UTC, Isaque Galdino
committed Details | Review
year-view: Fix for 01-01-2017 date (3.38 KB, patch)
2016-01-24 18:27 UTC, Isaque Galdino
none Details | Review
year-view: Fix for 01-01-2017 date (3.54 KB, patch)
2016-01-27 18:09 UTC, Isaque Galdino
none Details | Review
year-view: Fix for 01-01-2017 date (3.73 KB, patch)
2016-01-30 01:35 UTC, Isaque Galdino
committed Details | Review

Description Marcus Lundblad 2015-11-05 08:17:21 UTC
Using a locale with monday is start-of-week (sv_SE) if that matters…
Looking at the year view for 2015, you can see that the last week in 2015 (28-31 december) has four days in this year, and is correctly labelled as week #53.
Looking at the year view for 2016, you can see that the first week in 2016 (1-3 january) has 3 days in that year, and is incorrectly labelled as week #1, when is actually counted as week #53 in 2015 (as the week has more days in the previos year).
The calendar dropdown in the top menu (with week numbers turned on in the tweak tool) shows the correct behavior.
Comment 1 Erick Perez Castellanos 2015-11-06 22:04:01 UTC
(In reply to Marcus Lundblad from comment #0)
> Using a locale with monday is start-of-week (sv_SE) if that matters…
> Looking at the year view for 2015, you can see that the last week in 2015
> (28-31 december) has four days in this year, and is correctly labelled as
> week #53.
> Looking at the year view for 2016, you can see that the first week in 2016
> (1-3 january) has 3 days in that year, and is incorrectly labelled as week
> #1, when is actually counted as week #53 in 2015 (as the week has more days
> in the previos year).
> The calendar dropdown in the top menu (with week numbers turned on in the
> tweak tool) shows the correct behavior.

I don't believe that's wrong. Where are we getting the definition for week numbering?
Comment 2 Marcus Lundblad 2015-11-07 10:20:01 UTC
(In reply to Erick Pérez Castellanos from comment #1)
> (In reply to Marcus Lundblad from comment #0)
> > Using a locale with monday is start-of-week (sv_SE) if that matters…
> > Looking at the year view for 2015, you can see that the last week in 2015
> > (28-31 december) has four days in this year, and is correctly labelled as
> > week #53.
> > Looking at the year view for 2016, you can see that the first week in 2016
> > (1-3 january) has 3 days in that year, and is incorrectly labelled as week
> > #1, when is actually counted as week #53 in 2015 (as the week has more days
> > in the previos year).
> > The calendar dropdown in the top menu (with week numbers turned on in the
> > tweak tool) shows the correct behavior.
> 
> I don't believe that's wrong. Where are we getting the definition for week
> numbering?

I beg to differ! :-)
See this definition for the ISO week numbering: https://en.wikipedia.org/wiki/ISO_8601#Week_dates

So, if you check in the year view for 2016, you'll see that the first week in 2016, the one with Januari 1 in it, has 3 days in the new year (fri, sat, sun) which means that this is counted as the last week of the previous year (52 or 53, in this case 53, as 2015 is a "week 53 year").
Note that this is in a week-starts on monday locale.
It might be different in i.e. a en_US locale where the week starts on sunday.
Comment 3 Erick Perez Castellanos 2015-11-19 02:03:47 UTC
(In reply to Marcus Lundblad from comment #2)
> (In reply to Erick Pérez Castellanos from comment #1)
> > (In reply to Marcus Lundblad from comment #0)
> > > Using a locale with monday is start-of-week (sv_SE) if that matters…
> > > Looking at the year view for 2015, you can see that the last week in 2015
> > > (28-31 december) has four days in this year, and is correctly labelled as
> > > week #53.
> > > Looking at the year view for 2016, you can see that the first week in 2016
> > > (1-3 january) has 3 days in that year, and is incorrectly labelled as week
> > > #1, when is actually counted as week #53 in 2015 (as the week has more days
> > > in the previos year).
> > > The calendar dropdown in the top menu (with week numbers turned on in the
> > > tweak tool) shows the correct behavior.
> > 
> > I don't believe that's wrong. Where are we getting the definition for week
> > numbering?
> 
> I beg to differ! :-)
> See this definition for the ISO week numbering:
> https://en.wikipedia.org/wiki/ISO_8601#Week_dates
> 
> So, if you check in the year view for 2016, you'll see that the first week
> in 2016, the one with Januari 1 in it, has 3 days in the new year (fri, sat,
> sun) which means that this is counted as the last week of the previous year
> (52 or 53, in this case 53, as 2015 is a "week 53 year").
> Note that this is in a week-starts on monday locale.
> It might be different in i.e. a en_US locale where the week starts on sunday.

Ok, I'll read through and update the view as expected. Thank for pointing it out.
Comment 4 jarpit96 2015-12-10 16:07:15 UTC
I am trying to resolve this. Thanks.
Comment 5 Isaque Galdino 2016-01-19 03:38:46 UTC
Created attachment 319321 [details] [review]
gnome-calendar: Fix week #s in year view

Changed year view to use ISO 8601 standard to display the week #s
correctly when showing first and last weeks.

Year view was always starting week #s as 1, based on Jan 1st, and it
kept count the weeks until Dec 31st. But according to ISO 8601 standard,
that's not always true, i.e. Jan 1st 2016, is still in the 53th week of
2015, while Dec 31st 2014 is already in the 1st week of 2015.

Now the code is using ISO 8601 GDate function to get the correct week
number for the first and the last weeks of the year only. Other weeks
continue to use the same logic.

More about ISO 6801: https://en.wikipedia.org/wiki/ISO_8601#Week_dates
Comment 6 Georges Basile Stavracas Neto 2016-01-19 11:25:13 UTC
Review of attachment 319321 [details] [review]:

I just tried this patch and it mostly works. However, it shows 2017's first week wrongly (it should start with #1, but it actually starts with #53). That should be a small condition check that should be going wrong.
Comment 7 Georges Basile Stavracas Neto 2016-01-19 11:28:45 UTC
I'd like to point out that this commit message is perfect.
Comment 8 Isaque Galdino 2016-01-19 11:32:14 UTC
Murphy's Law, I've tested 2016, 2015 and 2014... Let me check it.
And thanks! :)
Comment 9 Isaque Galdino 2016-01-19 17:33:27 UTC
Created attachment 319367 [details] [review]
gnome-calendar: Fix week #s in year view

Changed year view to use ISO 8601 standard to display the week #s
correctly when showing first and last weeks.

Year view was always starting week #s as 1, based on Jan 1st, and it
kept count the weeks until Dec 31st. But according to ISO 8601 standard,
that's not always true, i.e. Jan 1st 2016, is still in the 53th week of
2015, while Dec 31st 2014 is already in the 1st week of 2015.

Now the code is using ISO 8601 GDate function to get the correct week
number for the first and the last weeks of the year only. Other weeks
continue to use the same logic.

More about ISO 6801: https://en.wikipedia.org/wiki/ISO_8601#Week_dates
Comment 10 Georges Basile Stavracas Neto 2016-01-19 20:13:37 UTC
Comment on attachment 319367 [details] [review]
gnome-calendar: Fix week #s in year view

Thanks! Now, we have to figure out what's going on that 01-01-2017 is displaying as week #52.

Didn't see any other issues besides that.

Attachment 319367 [details] pushed as c4853dd - gnome-calendar: Fix week #s in year view
Comment 11 Isaque Galdino 2016-01-22 21:14:55 UTC
I've managed to fix the 01-01-2017 and I compared first and last weeks of years from 2010-2020 and they are all OK.

I just need some advice in order to submit this new commit: should I create a new one or should I just use the last one?

Thanks.
Comment 12 Isaque Galdino 2016-01-22 21:15:46 UTC
Ops, I forgot to mention I compared the results with gnome-shell panel calendar.
Comment 13 Isaque Galdino 2016-01-24 18:27:28 UTC
Created attachment 319615 [details] [review]
year-view: Fix for 01-01-2017 date

Previous fix was considering Jan 1st and Dec 31st to find the week
number, using ISO 8601 standard, and that was causing an issue with some
dates like Jan 1st, 2017 which was displaying week# 52 instead of
week #1.

The issue happened because ISO 8601 always consider Monday as the first
weekday, so as Jan 1st, 2017 is a Sunday, it' still considered week# 52
and not week# 1.

After checking GtkCalendar code I noticed it uses the same ISO 8601
standard but instead of using Jan 1st or Dec 31st, it always get the
week number based on the last day of that week, taking account if the
week starts on Sunday or Monday, depending on the locale. In our
example, using a calendar based on Sunday, Jan 1st, 2017 is the first
day of the week and Jan 7th, 2017 is the last one. Therefore I changed
week number code to always use the last day of the week.
Comment 14 Georges Basile Stavracas Neto 2016-01-25 13:55:50 UTC
Review of attachment 319615 [details] [review]:

This patch does not compile against git master.
Comment 15 Isaque Galdino 2016-01-27 18:09:40 UTC
Created attachment 319869 [details] [review]
year-view: Fix for 01-01-2017 date

Previous fix was considering Jan 1st and Dec 31st to find the week
number, using ISO 8601 standard, and that was causing an issue with some
dates like Jan 1st, 2017 which was displaying week# 52 instead of
week #1.

The issue happened because ISO 8601 always consider Monday as the first
weekday, so as Jan 1st, 2017 is a Sunday, it' still considered week# 52
and not week# 1.

After checking GtkCalendar code I noticed it uses the same ISO 8601
standard but instead of using Jan 1st or Dec 31st, it always get the
week number based on the last day of that week, taking account if the
week starts on Sunday or Monday, depending on the locale. In our
example, using a calendar based on Sunday, Jan 1st, 2017 is the first
day of the week and Jan 7th, 2017 is the last one. Therefore I changed
week number code to always use the last day of the week.
Comment 16 Isaque Galdino 2016-01-30 01:35:54 UTC
Created attachment 320050 [details] [review]
year-view: Fix for 01-01-2017 date

Previous fix was considering Jan 1st and Dec 31st to find the week
number, using ISO 8601 standard, and that was causing an issue with some
dates like Jan 1st, 2017 which was displaying week# 52 instead of
week #1.

The issue happened because ISO 8601 always consider Monday as the first
weekday, so as Jan 1st, 2017 is a Sunday, it' still considered week# 52
and not week# 1.

After checking GtkCalendar code I noticed it uses the same ISO 8601
standard but instead of using Jan 1st or Dec 31st, it always get the
week number based on the last day of that week, taking account if the
week starts on Sunday or Monday, depending on the locale. In our
example, using a calendar based on Sunday, Jan 1st, 2017 is the first
day of the week and Jan 7th, 2017 is the last one. Therefore I changed
week number code to always use the last day of the week.
Comment 17 Georges Basile Stavracas Neto 2016-02-02 16:50:53 UTC
Thanks for working on this issue.

Attachment 320050 [details] pushed as 9646d4f - year-view: Fix for 01-01-2017 date