[Kstars-devel] kdeedu/libkdeedu/extdate
Jason Harris
kstars at 30doradus.org
Thu May 13 09:07:36 CEST 2004
CVS commit by harris:
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 at kde.org
M +3 -0 extdatetbl.cpp 1.2
M +27 -24 extdatetime.cpp 1.5
M +1 -1 extdatetime.h 1.3
--- kdeedu/libkdeedu/extdate/extdatetbl.cpp #1.1:1.2
@@ -32,4 +32,6 @@
// 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
--- kdeedu/libkdeedu/extdate/extdatetime.cpp #1.4:1.5
@@ -487,4 +487,18 @@ bool ExtDate::setYMD( int y, int m, int
}
+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
{
@@ -1064,32 +1078,21 @@ ExtDateTime ExtDateTime::addYears( int n
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;
-
- if ( nsecs < 0 ) {
- nsecs = -nsecs;
- sign = -1;
- }
+ tt += nsecs*1000;
- if ( nsecs >= (int)SECS_PER_DAY ) {
- dd += sign*(nsecs/SECS_PER_DAY);
- nsecs %= SECS_PER_DAY;
+ while ( tt < 0 ) {
+ tt += MSECS_PER_DAY;
+ --dd;
}
- 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;
--- kdeedu/libkdeedu/extdate/extdatetime.h #1.2:1.3
@@ -71,5 +71,5 @@ public:
#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;
More information about the Kstars-devel
mailing list