Bug 76000 - mismatch of week numbers
Summary: mismatch of week numbers
Status: RESOLVED FIXED
Alias: None
Product: korganizer
Classification: Applications
Component: general (show other bugs)
Version: 3.2
Platform: unspecified Linux
: NOR normal
Target Milestone: ---
Assignee: Cornelius Schumacher
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2004-02-24 10:04 UTC by Willem van Bergen
Modified: 2004-08-14 12:56 UTC (History)
0 users

See Also:
Latest Commit:
Version Fixed In:


Attachments
2004-07-30_KOrganizer_WeekNumDateMatrix_WeekStartNotMonday_Bug76000.patch (1.60 KB, patch)
2004-07-30 20:10 UTC, Reinhold Kainhofer
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Willem van Bergen 2004-02-24 10:04:11 UTC
Version:           3.2 (using KDE 3.2.0, Mandrake Linux Cooker i586 - Cooker)
Compiler:          gcc version 3.3.1 (Mandrake Linux 9.2 3.3.1-2mdk)
OS:          Linux (i686) release 2.4.22-10mdk

In the calendar on the top-left of the window, it tells me that Tuesday April 13 is in week 15. In fact, this is week 16.
Moreover, when I try to select a date when creating a new appointment using the dropdown calendar, I can choose week numbers as well. The week numbers seem to be correct: when I select week 16 over there, it will select April 13.
Comment 1 Cornelius Schumacher 2004-02-24 10:17:02 UTC
Can't reproduce the problem. For me April 13 is in week 16. What settings do you use? Could you attach a screenshot?
Comment 2 Willem van Bergen 2004-02-24 21:09:54 UTC
http://wwwhome.cs.utwente.nl/~bergen/snapshot.png

As you can see, in the calendar top-left April 13 is in week 15, while in the calendar on the middle, the dropdown menu tells me the same date is in week 16.

It might have something to do with the first day of the week (Sunday in my case).
Comment 3 Reinhold Kainhofer 2004-07-30 20:10:46 UTC
The attached patch fixes by 76000. 
According to the ISO definition, weeks always start on monday, with week #1 of 
a year being the week of the first thursday of the year (which means Jan 1 
might be in week 53 of the previous year!).

As a consequence, if the user set his week to start on a day different from 
Monday, a line in the day matrix will contain days from two differnt weeks. 
This patch shows both week numbers, like for July 2004:
        Sun Mon Tue Wed Thu Fri Sat
26/27   27  28  29  30   1   2   3
27/28    4   5   6   7   8   9  10
28/29   11  12  13  14  15  16  17
29/30   18  19  20  21  22  23  24
30/31   25  26  27  28  29  30  31

If a calendar system uses different week numbers, this is also included in the 
patch, as it uses KCalendarSystem.

Unfortunately KDE is in feature and string freeze for KDE 3.3, so I cannot 
apply this patch before kde 3.3 is released. This also means that the patch 
will only be released with kde 3.4...

Cheers,
Reinhold



Created an attachment (id=6934)
2004-07-30_KOrganizer_WeekNumDateMatrix_WeekStartNotMonday_Bug76000.patch
Comment 4 Reinhold Kainhofer 2004-08-14 12:55:59 UTC
CVS commit by kainhofe: 

Now that cvs head is open for commits again, apply the patch. If week start day is not monday, both week numbers are now shown like (for July 2004):
        Sun Mon Tue Wed Thu Fri Sat 
 26/27   27  28  29  30   1   2   3 
 27/28    4   5   6   7   8   9  10 
 28/29   11  12  13  14  15  16  17 
 29/30   18  19  20  21  22  23  24 
 30/31   25  26  27  28  29  30  31 
 

CCMAIL: 76000-done@bugs.kde.org


  M +13 -12    kdatenavigator.cpp   1.35


--- kdepim/korganizer/kdatenavigator.cpp  #1.34:1.35
@@ -190,18 +190,19 @@ void KDateNavigator::updateView()
 
   // set the week numbers.
+  const KCalendarSystem *calsys = KOGlobals::self()->calendarSystem();
   for( i = 0; i < 6; i++ ) {
+    // Use QDate's weekNumber method to determine the week number!
+    QDate dtStart = mDayMatrix->getDate( i * 7 );
+    QDate dtEnd = mDayMatrix->getDate( ( i + 1 ) * 7 - 1 );
+    int weeknumstart = calsys->weekNumber( dtStart );
+    int weeknumend = calsys->weekNumber( dtEnd );
     QString weeknum;
-    // remember, according to ISO 8601, the first week of the year is the
-    // first week that contains a thursday.  Thus we must subtract off 4,
-    // not just 1.
 
-    //ET int dayOfYear = buttons[(i + 1) * 7 - 4]->date().dayOfYear();
-    int dayOfYear = KOGlobals::self()->calendarSystem()->dayOfYear(
-        ( mDayMatrix->getDate( ( i + 1 ) * 7 - 4 ) ) );
-
-    if ( dayOfYear % 7 != 0 )
-      weeknum.setNum( dayOfYear / 7 + 1 );
-    else
-      weeknum.setNum( dayOfYear / 7 );
+    if ( weeknumstart != weeknumend ) {
+      weeknum = i18n("start/end week number of line in date picker", "%1/%2")
+                .arg( weeknumstart ).arg( weeknumend );
+    } else {
+      weeknum.setNum( weeknumstart );
+    }
     weeknos[i]->setText( weeknum );
   }