]> Git trees. - libqmvoc.git/commitdiff
Fix highlighting of the selected date in the ExtDatePicker widget
authorJason Harris <kstars@30doradus.org>
Thu, 19 Aug 2004 04:09:41 +0000 (04:09 +0000)
committerJason Harris <kstars@30doradus.org>
Thu, 19 Aug 2004 04:09:41 +0000 (04:09 +0000)
for years < 2000.  The highlighted date was off by one week because of a
bug in ExtDate::dayOfWeek().

Also, make ExtDate::addMonths() more robust.

This time I actually committed to the correct branch...

(TO BE BACKPORTED)

CCMAIL: kstars-devel@kde.org

svn path=/trunk/kdeedu/libkdeedu/; revision=338991

extdate/extdatetime.cpp

index 346df7d2ff2249b2b3f27df5e64e748904f4b33c..34fd8ccc0546dfe454b780b20c1024b83c6c676a 100644 (file)
@@ -280,6 +280,7 @@ int ExtDate::dayOfWeek() const
 {
        //JD 2451545 (01 Jan 2000) was a Saturday, which is dayOfWeek=6.
        int a_day = (( jd() - 2451545 + 6 ) % 7);
+       if ( a_day < 0 ) a_day += 7;
        return (a_day == 0) ? 7 : a_day;
 }
 
@@ -516,9 +517,14 @@ ExtDate ExtDate::addDays( int days ) const
 
 ExtDate  ExtDate::addMonths( int months ) const
 {
-       int     a_month = month() + months;
-       int     a_year = year() + (a_month - 1)/12;     // month : [1..12]
-       a_month  = 1 + (a_month -1) % 12;
+       int a_month = month() + months%12;
+       int a_year  = year()  + int(months/12);
+
+       while ( a_month < 1 ) {
+               a_month += 12;
+               a_year--;
+       }
+
        return ExtDate(a_year, a_month, day());
 }