]> Git trees. - libqmvoc.git/commitdiff
Fixing some problems in ExtDate and friends:
authorJason Harris <kstars@30doradus.org>
Thu, 13 May 2004 07:07:35 +0000 (07:07 +0000)
committerJason Harris <kstars@30doradus.org>
Thu, 13 May 2004 07:07:35 +0000 (07:07 +0000)
Fixed ExtDate::setJD() (did not set calendar date)
Fixed ExtDateTime::addSecs() (bad conversion from int to uint; simplified code)
(added author comment to extdatetbl.cpp)

CCMAIL: kstars-devel@kde.org

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

extdate/extdatetbl.cpp
extdate/extdatetime.cpp
extdate/extdatetime.h

index c774c6aba03e4c530b417c86a4b02b66f9594e1c..325f001e9fe93a45c761aafb10095f9c9af3a0bc 100644 (file)
@@ -31,6 +31,8 @@
 // Written using Qt (http://www.troll.no) for the
 // KDE project (http://www.kde.org)
 //
+// Modified to use ExtDate by Jason Harris, 2004
+//
 // This is a support class for the ExtDatePicker class.  It just
 // draws the calender table without titles, but could theoretically
 // be used as a standalone.
@@ -181,6 +183,7 @@ ExtDate ExtDateTable::dateFromPos( int pos )
   // adjust this <1 if more days should be forced visible:
   if ( offset < 1 ) offset += 7;
   pCellDate = d->calendar->addDays( pCellDate, pos - offset );
+
   return pCellDate;
 }
 
index 574067d8ef42eb2c1323637908d560ab3ae7b7d6..b5e1848e9670ceff5c2194d8f76b38b1a1f5ea01 100644 (file)
@@ -486,9 +486,23 @@ bool ExtDate::setYMD( int y, int m, int d )
        }
 }
 
+bool ExtDate::setJD( long int _jd ) {
+       if ( _jd == INVALID_DAY ) {
+               m_jd = _jd;
+               m_year = 0;
+               m_month = 0;
+               m_day = 0;
+               return false;
+       } else {
+               m_jd = _jd;
+               JDToGregorian( _jd, m_year, m_month, m_day );
+               return true;
+       }
+}
+
 ExtDate ExtDate::addDays( int days ) const
 {
-       ExtDate a_date;
+       ExtDate a_date;
        a_date.setJD( jd() + days );
        return a_date;
 }
@@ -1063,34 +1077,23 @@ ExtDateTime ExtDateTime::addYears( int nyears ) const
 
 ExtDateTime ExtDateTime::addSecs( int nsecs ) const
 {
-       uint dd = d.jd();
+       long int dd = d.jd();
        int tt = MSECS_PER_HOUR*t.hour() + MSECS_PER_MIN*t.minute() + 1000*t.second() + t.msec();
-       int  sign = 1;
+       tt += nsecs*1000;
 
-       if ( nsecs < 0 ) {
-               nsecs = -nsecs;
-               sign = -1;
+       while ( tt < 0 ) {
+               tt += MSECS_PER_DAY;
+               --dd;
        }
 
-       if ( nsecs >= (int)SECS_PER_DAY ) {
-               dd += sign*(nsecs/SECS_PER_DAY);
-               nsecs %= SECS_PER_DAY;
-       }
-       tt += sign*nsecs*1000;
-
-       if ( tt < 0 ) {
-               tt = MSECS_PER_DAY - tt - 1;
-               dd -= tt / MSECS_PER_DAY;
-               tt = tt % MSECS_PER_DAY;
-               tt = MSECS_PER_DAY - tt - 1;
-       } else if ( tt >= (int)MSECS_PER_DAY ) {
-               dd += ( tt / MSECS_PER_DAY );
-               tt = tt % MSECS_PER_DAY;
+       while ( tt > MSECS_PER_DAY ) {
+               tt -= MSECS_PER_DAY;
+               ++dd;
        }
 
        ExtDateTime ret;
-       ret.setTime( ret.t.addMSecs( tt ) );
-       ret.d.setJD( dd );
+       ret.setTime( QTime().addMSecs( tt ) );
+       ret.setDate( ExtDate( dd ) );
 
        return ret;
 }
index 0f0dd7fdc135dd8c14e81b4c1421b0dc697b9bef..1dc5da407884f2426e053361f405150b52960db5 100644 (file)
@@ -70,7 +70,7 @@ public:
        QString toString( const QString& format ) const;
 #endif
        bool setYMD( int y, int m, int d );
-       void setJD( long int _jd ) { m_jd = _jd; }
+       bool setJD( long int _jd );
 
        ExtDate addDays( int days ) const;
        ExtDate addMonths( int months ) const;