Add support for parsing time strings
This lets us take time strings as command line arguments pretty easily
and manipulate them
Change-Id: I7971cce24a71933c9c1fa9fd13555848efc5964e
diff --git a/aos/time/time.h b/aos/time/time.h
index e31de5c..0bd0708 100644
--- a/aos/time/time.h
+++ b/aos/time/time.h
@@ -6,6 +6,7 @@
#include <time.h>
#include <chrono>
+#include <optional>
#include <ostream>
#include <thread>
#include <type_traits>
@@ -27,6 +28,11 @@
// not steady.
static constexpr bool is_steady = false;
+ // Converts the time string to a time_point if it is well formatted. This is
+ // designed to reverse operator <<.
+ static std::optional<monotonic_clock::time_point> FromString(
+ const std::string_view now);
+
// Returns the epoch (0).
static constexpr monotonic_clock::time_point epoch() {
return time_point(zero());
@@ -52,6 +58,11 @@
#endif // __linux__
static constexpr bool is_steady = false;
+ // Converts the time string to a time_point if it is well formatted. This is
+ // designed to reverse operator <<.
+ static std::optional<realtime_clock::time_point> FromString(
+ const std::string_view now);
+
// Returns the epoch (0).
static constexpr realtime_clock::time_point epoch() {
return time_point(zero());