From 583edd8067b71ce5c8c742a6f0bf3562f138d872 Mon Sep 17 00:00:00 2001 From: Jason Harris Date: Thu, 13 May 2004 07:07:35 +0000 Subject: [PATCH] Fixing some problems in ExtDate and friends: 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 | 3 +++ extdate/extdatetime.cpp | 47 ++++++++++++++++++++++------------------- extdate/extdatetime.h | 2 +- 3 files changed, 29 insertions(+), 23 deletions(-) diff --git a/extdate/extdatetbl.cpp b/extdate/extdatetbl.cpp index c774c6a..325f001 100644 --- a/extdate/extdatetbl.cpp +++ b/extdate/extdatetbl.cpp @@ -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; } diff --git a/extdate/extdatetime.cpp b/extdate/extdatetime.cpp index 574067d..b5e1848 100644 --- a/extdate/extdatetime.cpp +++ b/extdate/extdatetime.cpp @@ -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; } diff --git a/extdate/extdatetime.h b/extdate/extdatetime.h index 0f0dd7f..1dc5da4 100644 --- a/extdate/extdatetime.h +++ b/extdate/extdatetime.h @@ -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; -- 2.47.3