Make a DurationInSeconds function
Also, run clang-format on all the files I changed because I am too lazy
to figure out how to call clang-format on just the lines I changed.
Change-Id: I071c6f81dced533a0a269f25a258348132a7056a
diff --git a/aos/time/time.h b/aos/time/time.h
index 0333c5c..469534f 100644
--- a/aos/time/time.h
+++ b/aos/time/time.h
@@ -2,17 +2,16 @@
#define AOS_TIME_H_
#include <stdint.h>
-#include <time.h>
#include <sys/time.h>
-#include <stdint.h>
+#include <time.h>
-#include <type_traits>
#include <chrono>
-#include <thread>
#include <ostream>
+#include <thread>
+#include <type_traits>
-#include "aos/type_traits/type_traits.h"
#include "aos/macros.h"
+#include "aos/type_traits/type_traits.h"
namespace aos {
@@ -98,6 +97,16 @@
hertz;
}
+template <typename Scalar>
+constexpr Scalar TypedDurationInSeconds(monotonic_clock::duration dt) {
+ return ::std::chrono::duration_cast<::std::chrono::duration<Scalar>>(dt)
+ .count();
+}
+
+constexpr double DurationInSeconds(monotonic_clock::duration dt) {
+ return TypedDurationInSeconds<double>(dt);
+}
+
// RAII class that freezes monotonic_clock::now() (to avoid making large numbers
// of syscalls to find the real time).
class TimeFreezer {