[Kstars-devel] KDE/kdeedu/kstars/kstars

Jason Harris kstars at 30doradus.org
Wed Dec 19 07:17:16 CET 2007


SVN commit 750311 by harris:

Fix the KStarsDateTime ctor that takes a QDateTime argument.  I don't
fully understand why the old version didn't work, but it produced "nan"
for the DJD value...

CCMAIL: kstars-devel at kde.org



 M  +10 -1     kstarsdatetime.cpp  
 M  +100 -99   kstarsdatetime.h  


--- trunk/KDE/kdeedu/kstars/kstars/kstarsdatetime.cpp #750310:750311
@@ -44,7 +44,10 @@
 }
 
 KStarsDateTime::KStarsDateTime( const QDateTime &qdt ) : KDateTime( qdt, KDateTime::Spec::UTC() ) {
-    KStarsDateTime( KDateTime( qdt, KDateTime::Spec::UTC() ) );
+    QTime _t = qdt.time();
+    QDate _d = qdt.date();
+    long double jdFrac = ( _t.hour()-12 + ( _t.minute() + ( _t.second() + _t.msec()/1000.)/60.)/60.)/24.;
+    DJD = (long double)( _d.toJulianDay() ) + jdFrac;
 }
 
 KStarsDateTime::KStarsDateTime( const QDate &_d, const QTime &_t )
@@ -120,6 +123,12 @@
     setDJD( (long double)_d.toJulianDay() + jdFrac );
 }
 
+KStarsDateTime KStarsDateTime::addSecs( double s ) const { 
+    long double ds = (long double)s/86400.;
+    KStarsDateTime kdt( djd() + ds );
+    return kdt;
+}
+
 void KStarsDateTime::setTime( const QTime &_t ) {
     KStarsDateTime _dt( date(), _t );
     setDJD( _dt.djd() );
--- trunk/KDE/kdeedu/kstars/kstars/kstarsdatetime.h #750310:750311
@@ -27,106 +27,107 @@
 class dms;
 
 /**@class KStarsDateTime
-  *@short Extension of KDateTime for KStars
-  *KStarsDateTime can represent the date/time as a Julian Day, using a long double, 
-  *in which the fractional portion encodes the time of day to a precision of a less than a second.
-  *Also adds Greenwich Sidereal Time and "epoch", which is just the date expressed as a floating
-  *point number representing the year, with the fractional part representing the date and time 
-  *(with poor time resolution; typically the Epoch is only taken to the hundredths place, which is 
-  *a few days).
-  *@note Local time and Local sideral time are not handled here.  Because they depend on the 
-  *geographic location, they are part of the GeoLocation class.
-  *@sa GeoLocation::GSTtoLST()
-  *@sa GeoLocation::UTtoLT()
-  *@author Jason Harris
-  *@version 1.0
-  */
+ *@short Extension of KDateTime for KStars
+ *KStarsDateTime can represent the date/time as a Julian Day, using a long double, 
+ *in which the fractional portion encodes the time of day to a precision of a less than a second.
+ *Also adds Greenwich Sidereal Time and "epoch", which is just the date expressed as a floating
+ *point number representing the year, with the fractional part representing the date and time
+ *(with poor time resolution; typically the Epoch is only taken to the hundredths place, which is 
+ *a few days).
+ *@note Local time and Local sideral time are not handled here.  Because they depend on the 
+ *geographic location, they are part of the GeoLocation class.
+ *@sa GeoLocation::GSTtoLST()
+ *@sa GeoLocation::UTtoLT()
+ *@author Jason Harris
+ *@version 1.0
+ */
 
 class KStarsDateTime : public KDateTime
 {
 public:
     /**
-    	*@short Default constructor  
-    	*Creates a date/time at J2000 (noon on Jan 1, 200)
-    	*/
+     *@short Default constructor  
+     *Creates a date/time at J2000 (noon on Jan 1, 200)
+     */
     KStarsDateTime();
 
     /**
-    	*@short Constructor  
-    	*Creates a date/time at the specified Julian Day.
-    	*@p jd The Julian Day
-    	*/
+     *@short Constructor  
+     *Creates a date/time at the specified Julian Day.
+     *@p jd The Julian Day
+     */
     KStarsDateTime( long int jd );
 
     /**
-    	*@short Constructor  
-    	*Creates a date/time at the specified Julian Day.
-    	*@p jd The Julian Day
-    	*/
+     *@short Constructor  
+     *Creates a date/time at the specified Julian Day.
+     *@p jd The Julian Day
+     */
     KStarsDateTime( double djd );
 
     /**
-    	*@short Constructor  
-    	*Creates a date/time at the specified Julian Day.
-    	*@p jd The Julian Day
-    	*/
+     *@short Constructor  
+     *Creates a date/time at the specified Julian Day.
+     *@p jd The Julian Day
+     */
     KStarsDateTime( long double djd );
 
     /**
-    	*@short Copy constructor
-    	*@p kdt The KStarsDateTime object to copy.
-    	*/
+     *@short Copy constructor
+     *@p kdt The KStarsDateTime object to copy.
+     */
     KStarsDateTime( const KStarsDateTime &kdt );
 
     /**
-    	*@short Copy constructor
-    	*@p kdt The KDateTime object to copy.
-    	*/
+     *@short Copy constructor
+     *@p kdt The KDateTime object to copy.
+     */
     KStarsDateTime( const KDateTime &kdt );
 
     /**
-    	*@short Copy constructor
-    	*@p qdt The QDateTime object to copy.
-    	*/
+     *@short Copy constructor
+     *@p qdt The QDateTime object to copy.
+     */
     KStarsDateTime( const QDateTime &qdt );
 
     /**
-    	*@short Constructor
-    	*Create a KStarsDateTimne based on the specified Date and Time.
-    	*@p _d The QDate to assign
-    	*@p _t The QTime to assign
-    	*/
+     *@short Constructor
+     *Create a KStarsDateTimne based on the specified Date and Time.
+     *@p _d The QDate to assign
+     *@p _t The QTime to assign
+     */
     KStarsDateTime( const QDate &_d, const QTime &_t );
 
     /**
-    	*Assign the (long double) Julian Day value, which includes the time of day
-    	*encoded in the fractional portion.
-    	*@p jd the Julian Day value to assign.
-    	*/
+     *Assign the (long double) Julian Day value, which includes the time of day
+     *encoded in the fractional portion.
+     *@p jd the Julian Day value to assign.
+     */
     void setDJD( long double jd );
 
     /**
-    	*Assign the Date according to a QDate object.
-    	*@p d the QDate to assign
-    	*/
+     *Assign the Date according to a QDate object.
+     *@p d the QDate to assign
+     */
     void setDate( const QDate &d );
 
     /**
-    	*Assign the Time according to a QTime object.
-    	*@p t the QTime to assign
-    	*/
+     *Assign the Time according to a QTime object.
+     *@p t the QTime to assign
+     */
     void setTime( const QTime &t );
 
     /**
-    	*Modify the Date/Time by adding a number of seconds.  
-    	*@p s the number of seconds to add.  The number can be negative.
-    	*/
-    inline KStarsDateTime addSecs( double s ) const { return KStarsDateTime( djd() + (long double)s/86400. ); }
+     *@return a KStarsDateTime that is the given number of seconds later 
+     *than this KStarsDateTime.  
+     *@p s the number of seconds to add.  The number can be negative.
+     */
+    KStarsDateTime addSecs( double s ) const;
 
     /**
-    	*Modify the Date/Time by adding a number of days.  
-    	*@p nd the number of days to add.  The number can be negative.
-    	*/
+     *Modify the Date/Time by adding a number of days.  
+     *@p nd the number of days to add.  The number can be negative.
+     */
     inline KStarsDateTime addDays( int nd ) const { return KStarsDateTime( djd() + (long double)nd ); }
 
     inline bool operator == ( const KStarsDateTime &d ) const { return DJD == d.djd(); }
@@ -137,11 +138,11 @@
     inline bool operator >= ( const KStarsDateTime &d ) const { return DJD >= d.djd(); }
 
     /**
-    	*@return the date and time according to the CPU clock
-    	*@p ts a Qt::TimeSpec value that determines whether the date is
-    	*computed from the Local Time or the Universal Time.
-    	*@sa Qt::TimeSpec
-    	*/
+     *@return the date and time according to the CPU clock
+     *@p ts a Qt::TimeSpec value that determines whether the date is
+     *computed from the Local Time or the Universal Time.
+     *@sa Qt::TimeSpec
+     */
     static KStarsDateTime currentDateTime(KDateTime::Spec ts = KDateTime::Spec::ClockTime());
 
     /**
@@ -153,69 +154,69 @@
     static KStarsDateTime fromString( const QString &s );
 
     /**
-    	*@return the julian day as a long double, including the time as the fractional portion.
-    	*/
+     *@return the julian day as a long double, including the time as the fractional portion.
+     */
     inline long double djd() const { return DJD; }
 
     /**
-    	*@return the fraction of the Julian Day corresponding to the current time.
-    	*Because the integer Julian Day value jd() is referenced to Noon on the current date,
-    	*jdFrac() ranges between values of -0.5 and +0.5 for the previous and next midnights,
-    	*respectively.
-    	*/
+     *@return the fraction of the Julian Day corresponding to the current time.
+     *Because the integer Julian Day value jd() is referenced to Noon on the current date,
+     *jdFrac() ranges between values of -0.5 and +0.5 for the previous and next midnights,
+     *respectively.
+     */
     inline double jdFrac() const { return ((time().hour()-12) + (time().minute()
                                         + (time().second() + time().msec()/1000.)/60.)/60.)/24.; }
 
     /**
-    	*@return the Julian Day value for the current date, but at 0h UT.  
-    	*@note the returned value is always an integer value + 0.5.
-    	*/
+     *@return the Julian Day value for the current date, but at 0h UT.  
+     *@note the returned value is always an integer value + 0.5.
+     */
     inline long double JDat0hUT() const { return int( djd() - 0.5 ) + 0.5; }
 
     /**
-    	*@return The Greenwich Sidereal Time
-    	*The Greenwich sidereal time is the Right Ascension coordinate that is currently transiting 
-    	*the Prime Meridian at the Royal Observatory in Greenwich, UK (longitude=0.0)
-    	*/
+     *@return The Greenwich Sidereal Time
+     *The Greenwich sidereal time is the Right Ascension coordinate that is currently transiting 
+     *the Prime Meridian at the Royal Observatory in Greenwich, UK (longitude=0.0)
+     */
     dms gst() const;
 
     /**
-    	*Convert a given Greenwich Sidereal Time to Universal Time (=Greenwich Mean Time).
-    	*@p GST the Greenwich Sidereal Time to convert to Universal Time.
-    	*/
+     *Convert a given Greenwich Sidereal Time to Universal Time (=Greenwich Mean Time).
+     *@p GST the Greenwich Sidereal Time to convert to Universal Time.
+     */
     QTime GSTtoUT( dms GST ) const;
 
 
     /**
-    	*@return the epoch value of the Date/Time.
-    	*@note the epoch is shorthand for the date, expressed as a floating-point year value.
-    	*@sa setFromEpoch()
-    	*/
+     *@return the epoch value of the Date/Time.
+     *@note the epoch is shorthand for the date, expressed as a floating-point year value.
+     *@sa setFromEpoch()
+     */
     inline double epoch() const { return ( double( date().year() )
                                         + double( date().dayOfYear() )/double( date().daysInYear() ) ); }
 
     /**
-    	*Set the Date/Time from an epoch value, represented as a double.
-    	*@p e the epoch value
-    	*@return true if date set successfully
-    	*@sa epoch()
-    	*/
+     *Set the Date/Time from an epoch value, represented as a double.
+     *@p e the epoch value
+     *@return true if date set successfully
+     *@sa epoch()
+     */
     bool setFromEpoch( double e );
 
     /**
-    	*Set the Date/Time from an epoch value, represented as a string.
-    	*@p e the epoch value
-    	*@return true if date set successfully
-    	*@sa epoch()
-    	*/
+     *Set the Date/Time from an epoch value, represented as a string.
+     *@p e the epoch value
+     *@return true if date set successfully
+     *@sa epoch()
+     */
     bool setFromEpoch( const QString &e );
 
 
 private:
     /**
-    	*@return the Greenwich Sidereal Time at 0h UT on this object's Date
-    	*@note used internally by gst() and GSTtoUT()
-    	*/
+     *@return the Greenwich Sidereal Time at 0h UT on this object's Date
+     *@note used internally by gst() and GSTtoUT()
+     */
     dms GSTat0hUT() const;
 
     long double DJD;


More information about the Kstars-devel mailing list