RTC Toolkit 5.1.0
Loading...
Searching...
No Matches
timeString.hpp
Go to the documentation of this file.
1
13#ifndef RTCTK_COMPONENTFRAMEWORK_TIMESTRING_HPP
14#define RTCTK_COMPONENTFRAMEWORK_TIMESTRING_HPP
15
17
18#include <chrono>
19#include <string>
20
22
28struct TimeString {
29 TimeString() = default;
30
34 operator std::string() const;
35
39 std::string ToString() const;
40
44 bool operator==(const TimeString&) const = default; // NOLINT
45
51 TimeString(const std::string& str);
52
58 TimeString(const char* str); // NOLINT
59
63 template <typename Clock, typename Duration = typename Clock::duration>
64 TimeString(std::chrono::time_point<Clock, Duration> timepoint)
65 : value(std::format(
66 "{0:%F}T{0:%T}.{1:03d}Z",
67 std::chrono::floor<std::chrono::seconds>(timepoint),
68 std::chrono::duration_cast<std::chrono::milliseconds>(timepoint.time_since_epoch())
69 .count() %
70 1000)) {
71 }
72
76 TimeString(std::chrono::nanoseconds ns_since_epoch);
77
82
83 std::string value;
84};
85
86void to_json(JsonPayload& j, const TimeString& e); // NOLINT
87void from_json(const JsonPayload& j, TimeString& e); // NOLINT
88
89} // namespace rtctk::componentFramework
90
91#endif // RTCTK_COMPONENTFRAMEWORK_TIMESTRING_HPP
Defines the JSON payload type JsonPayload.
Definition commandReplier.cpp:22
void to_json(JsonPayload &j, const std::vector< DataPointPath > &v)
Definition dataPointPath.cpp:207
nlohmann::json JsonPayload
Type requirements:
Definition jsonPayload.hpp:25
void from_json(const JsonPayload &j, std::vector< DataPointPath > &v)
Definition dataPointPath.cpp:217
elt::mal::future< std::string > InjectReqRepEvent(StateMachineEngine &engine)
Definition malEventInjector.hpp:23
Represents an ISO 8601 time string in format: YYYY-MM-DDThh:mm:ss.sssZ.
Definition timeString.hpp:28
bool operator==(const TimeString &) const =default
Operator to test equality.
TimeString(std::chrono::time_point< Clock, Duration > timepoint)
Constructs TimeString from chrono timepoint.
Definition timeString.hpp:64
std::string ToString() const
Explicit conversion to std::string.
Definition timeString.cpp:70
std::string value
Definition timeString.hpp:83