RTC Toolkit 6.0.0
Loading...
Searching...
No Matches
timeString.hpp
Go to the documentation of this file.
1
11
12#ifndef RTCTK_COMPONENTFRAMEWORK_TIMESTRING_HPP
13#define RTCTK_COMPONENTFRAMEWORK_TIMESTRING_HPP
14
16
17#include <chrono>
18#include <string>
19
21
27struct TimeString {
28 TimeString() = default;
29
33 operator std::string() const;
34
38 const std::string& ToString() const;
39
43 bool operator==(const TimeString&) const = default; // NOLINT
44
50 // Implicit conversions should be allowed for TimeString.
51 // cppcheck-suppress noExplicitConstructor
52 TimeString(const std::string& str);
53
59 // cppcheck-suppress noExplicitConstructor
60 TimeString(const char* str); // NOLINT
61
65 template <typename Clock, typename Duration = typename Clock::duration>
66 // cppcheck-suppress noExplicitConstructor
67 TimeString(std::chrono::time_point<Clock, Duration> timepoint)
68 : value(std::format(
69 "{0:%F}T{0:%T}.{1:03d}Z",
70 std::chrono::floor<std::chrono::seconds>(timepoint),
71 std::chrono::duration_cast<std::chrono::milliseconds>(timepoint.time_since_epoch())
72 .count() %
73 1000)) {
74 }
75
79 // cppcheck-suppress noExplicitConstructor
80 TimeString(std::chrono::nanoseconds ns_since_epoch);
81
85 // cppcheck-suppress noExplicitConstructor
86 TimeString(uint64_t ns_since_epoch);
87
88 std::string value;
89};
90
91void to_json(JsonPayload& j, const TimeString& e); // NOLINT
92void from_json(const JsonPayload& j, TimeString& e); // NOLINT
93
94} // namespace rtctk::componentFramework
95
96#endif // RTCTK_COMPONENTFRAMEWORK_TIMESTRING_HPP
Defines the JSON payload type JsonPayload.
Definition commandReplier.cpp:21
void to_json(JsonPayload &j, const DataPointPath &v)
Definition dataPointPath.cpp:217
nlohmann::json JsonPayload
Type requirements:
Definition jsonPayload.hpp:24
void from_json(const JsonPayload &j, DataPointPath &v)
Definition dataPointPath.cpp:222
Definition ddsSub.hpp:155
Represents an ISO 8601 time string in format: YYYY-MM-DDThh:mm:ss.sssZ.
Definition timeString.hpp:27
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:67
const std::string & ToString() const
Explicit conversion to std::string.
Definition timeString.cpp:69
std::string value
Definition timeString.hpp:88