static const double SIDRATE = 0.9972695677;
-SGTime::SGTime( double lon, double lat, const string& root )
+SGTime::SGTime( double lon, double lat, const string& root, time_t init_time )
{
SG_LOG( SG_EVENT, SG_INFO, "Initializing Time" );
gst_diff = -9999.0;
- cur_time = time(NULL);
+ if ( init_time ) {
+ cur_time = init_time;
+ } else {
+ cur_time = time(NULL);
+ }
+
cout << "Current greenwich mean time = " << asctime(gmtime(&cur_time))
<< endl;
cout << "Current local time = "
// Update the time related variables
-void SGTime::update( double lon, double lat, long int warp ) {
+void SGTime::update( double lon, double lat, time_t ct, long int warp ) {
double gst_precise, gst_course;
#if defined(_MSC_VER) || defined(__MINGW32__)
// get current Unix calendar time (in seconds)
// warp += warp_delta;
- cur_time = time(NULL) + warp;
+ if ( ct ) {
+ cur_time = ct + warp;
+ } else {
+ cur_time = time(NULL) + warp;
+ }
SG_LOG( SG_EVENT, SG_DEBUG,
" Current Unix calendar time = " << cur_time
<< " warp = " << warp );
// return the current modified Julian date (number of days elapsed
// since 1900 jan 0.5), mjd.
-double sgTimeCurrentMJD( long int warp ) {
+double sgTimeCurrentMJD( time_t ct, long int warp ) {
#if defined(_MSC_VER) || defined(__MINGW32__)
struct tm m_gmt; // copy of system gmtime(&time_t) structure
* 0).
* @param lon current longitude
* @param lat current latitude
- * @param root root path point to data file location (timezone, etc.) */
- SGTime( double lon, double lat, const string& root );
+ * @param root root path point to data file location (timezone, etc.)
+ * @param init_time provide an initialization time, 0 means use
+ current clock time */
+ SGTime( double lon, double lat, const string& root, time_t init_time = 0 );
/**
* Create an instance given a data file path.
* every frame.
* @param lon current longitude
* @param lat current latitude
+ * @param ct specify a unix time, otherwise specify 0 to use current
+ clock time
* @param warp an optional time offset specified in seconds. This
* allows us to advance or rewind "time" if we choose to. */
- void update( double lon, double lat, long int warp = 0 );
+ void update( double lon, double lat, time_t ct = 0, long int warp = 0 );
/**
* Given lon/lat, update timezone information and local_offset
* \relates SGTime
* Given an optional offset from current time calculate the current
* modified julian date.
+ * @param ct specify a unix time, otherwise specify 0 to use current
+ clock time
* @param warp number of seconds to offset from current time (0 if no offset)
* @return current modified Julian date (number of days elapsed
* since 1900 jan 0.5), mjd. */
-double sgTimeCurrentMJD( long int warp );
+double sgTimeCurrentMJD( time_t ct = 0, long int warp = 0 );
/**
* \relates SGTime