diff --git a/include/openspace/util/time.h b/include/openspace/util/time.h index 505e3d6321..345a5be062 100644 --- a/include/openspace/util/time.h +++ b/include/openspace/util/time.h @@ -58,7 +58,7 @@ class SyncBuffer; class Time { public: - Time(); + Time(double secondsJ2000 = -1); Time(const Time& other); @@ -77,6 +77,8 @@ public: */ static void deinitialize(); + static Time now(); + /** * Returns the reference to the Time singleton object. * \return The reference to the Time singleton object @@ -120,6 +122,8 @@ public: */ double currentTime() const; + double unsyncedJ2000Seconds() const; + /** * Returns the current time as a formatted date string compliant with ISO 8601 and * thus also compliant with the Spice library. diff --git a/src/util/time.cpp b/src/util/time.cpp index fbe7fc8a5c..7224a6de49 100644 --- a/src/util/time.cpp +++ b/src/util/time.cpp @@ -24,6 +24,8 @@ #include +#include + #include "time_lua.inl" #include @@ -33,12 +35,14 @@ #include + + namespace openspace { Time* Time::_instance = nullptr; -Time::Time() - : _time(-1.0) +Time::Time(double secondsJ2000) + : _time(secondsJ2000) , _dt(1.0) //local copies , _timeJumped(false) @@ -92,6 +96,17 @@ Time& Time::ref() { return *_instance; } +Time Time::now() { + Time now; + time_t secondsSince1970; + secondsSince1970 = time(nullptr); + time_t secondsInAYear = 365.25 * 24 * 60 * 60; + double secondsSince2000 = (double)(secondsSince1970 - 30*secondsInAYear); + now.setTime(secondsSince2000); + return now; +} + + bool Time::isInitialized() { return (_instance != nullptr); } @@ -105,6 +120,10 @@ double Time::currentTime() const { return _syncedTime; } +double Time::unsyncedJ2000Seconds() const { + return _time; +} + double Time::advanceTime(double tickTime) { if (_timePaused) return _time; @@ -139,7 +158,7 @@ std::string Time::currentTimeUTC() const { } std::string Time::ISO8601() const { - std::string datetime = currentTimeUTC(); + std::string datetime = SpiceManager::ref().dateFromEphemerisTime(_time); std::string month = datetime.substr(5, 3); std::string MM = "";