diff --git a/simgear/timing/timestamp.cxx b/simgear/timing/timestamp.cxx index f7e9fdf4..7553d322 100644 --- a/simgear/timing/timestamp.cxx +++ b/simgear/timing/timestamp.cxx @@ -29,6 +29,7 @@ #include #include +#include #ifdef HAVE_UNISTD_H # include // for gettimeofday() and the _POSIX_TIMERS define @@ -98,6 +99,21 @@ void SGTimeStamp::stamp() #endif } +void SGTimeStamp::systemClockHoursAndMinutes() +{ + using namespace std; + using namespace std::chrono; + + typedef duration >::type> days; + + system_clock::time_point now = system_clock::now(); + system_clock::duration tp = now.time_since_epoch(); + tp -= duration_cast(tp); + + _sec = duration_cast(tp).count(); + _nsec = duration_cast(tp - seconds(_sec)).count(); +} + // sleep based timing loop. // // Calling sleep, even usleep() on linux is less accurate than diff --git a/simgear/timing/timestamp.hxx b/simgear/timing/timestamp.hxx index ac9ca142..266fd2ab 100644 --- a/simgear/timing/timestamp.hxx +++ b/simgear/timing/timestamp.hxx @@ -78,6 +78,13 @@ public: /** Update stored time to current time (seconds and nanoseconds) */ void stamp(); + /** Update stored time to current system clock (seconds and nanoseconds) + * non monotonic, keeping only hours, minutes, seconds and decimals, + * so restart at 0 at midnight. + * using the std::chrono libs + */ + void systemClockHoursAndMinutes(); + /** Set the time from a double value */ void setTime(const double& seconds) {