[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-commits
Subject:    kdelibs/kdeui
From:       Charles Samuels <charles () kde ! org>
Date:       2005-05-02 0:01:34
Message-ID: 20050502000134.C1CB03EF () office ! kde ! org
[Download RAW message or body]

CVS commit by charles: 

Use calendar system specific date to calcuate week numbers, so week numbers
work for non-Gregorian systems as well. Tested on Gregorian, Hijri, Hebrew, 
and Jalali calender systems and seems to work fine.  At least Gregorian
works as before, but now the other calendar systems do as well.

This patch contributed by liucougar@gmail.com.  Thank you.

CCMAIL:liucougar@gmail.com


  M +15 -7     kdatepicker.cpp   1.74


--- kdelibs/kdeui/kdatepicker.cpp  #1.73:1.74
@@ -75,14 +75,22 @@ void KDatePicker::fillWeeksCombo(const Q
   // This of course can be a list like 53,1,2..52
 
-  QDate day(date.year(), 1, 1);
+  QDate day;
+  int year = calendar->year(date);
+  calendar->setYMD(day, year, 1, 1);
   int lastMonth = calendar->monthsInYear(day);
-  QDate lastDay(date.year(), lastMonth, calendar->daysInMonth(QDate(date.year(), \
lastMonth, 1))); +  QDate lastDay, firstDayOfLastMonth;
+  calendar->setYMD(firstDayOfLastMonth, year, lastMonth, 1);
+  calendar->setYMD(lastDay, year, lastMonth, \
calendar->daysInMonth(firstDayOfLastMonth));  
-  for (; day <= lastDay; day = calendar->addDays(day, 7 /*calendar->daysOfWeek()*/) \
) +  for (; day <= lastDay ; day = calendar->addDays(day, 7 \
/*calendar->daysOfWeek()*/) )  {
-    int year = 0;
     QString week = i18n("Week %1").arg(calendar->weekNumber(day, &year));
-    if ( year != date.year() ) week += "*";  // show that this is a week from a \
different year +    if ( year != calendar->year(day) ) week += "*";  // show that \
this is a week from a different year  d->selectWeek->insertItem(week);
+
+    // make sure that the week of the lastDay is always inserted: in Chinese \
calendar +    // system, this is not always the case
+    if(day < lastDay && day.daysTo(lastDay) < 7 && calendar->weekNumber(day) != \
calendar->weekNumber(lastDay)) +      day = lastDay.addDays(-7);
   }
 }
@@ -246,7 +254,7 @@ KDatePicker::dateChangedSlot(QDate date)
 
     // calculate the item num in the week combo box; normalize selected day so as if \
                1.1. is the first day of the week
-    QDate firstDay(date.year(), 1, 1);
+    QDate firstDay;
+    calendar->setYMD(firstDay, calendar->year(date), 1, 1);
     d->selectWeek->setCurrentItem((calendar->dayOfYear(date) + \
                calendar->dayOfWeek(firstDay) - 2) / 7/*calendar->daysInWeek()*/);
-
     selectYear->setText(calendar->yearString(date, false));
 


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic