67 using time_point_t = std::chrono::time_point<system_clock_t, duration_t>;
124 std::lock_guard<std::mutex> lk(time_mutex::get());
126 auto tt = system_clock_t::to_time_t(tp);
127 auto tm_utc = *std::gmtime(&tt);
138 std::lock_guard<std::mutex> lk(time_mutex::get());
140 auto tt = system_clock_t::to_time_t(tp);
141 auto tm_local = *std::localtime(&tt);
150 static constexpr char fmt[] =
"%FT%TZ";
152 return iso_8601(fmt, &tm);
160 static constexpr char fmt[] =
"%FT%T%z";
162 return iso_8601(fmt, &tm);
173 auto now = system_clock_t::now();
174 auto d =
now.time_since_epoch();
175 return {std::chrono::duration_cast<duration_t>(d).
count()};
185 static std::string iso_8601(
const char* fmt, std::tm* tm) {
187 std::strftime(buf,
sizeof(buf)-1, fmt, tm);
201 static std::mutex& get() {
202 static std::mutex mtx_time__;
A point in time.
Definition tec_timestamp.hpp:53
std::chrono::nanoseconds duration_t
Duration unit used by this timestamp (nanoseconds)
Definition tec_timestamp.hpp:61
std::string utc_time_str() const
Returns ISO 8601 string in UTC (with Z suffix)
Definition tec_timestamp.hpp:149
duration_t dur() const
Returns the duration since epoch as std::chrono::nanoseconds.
Definition tec_timestamp.hpp:112
int64_t count_t
Underlying integer type used to store nanosecond count.
Definition tec_timestamp.hpp:58
static Timestamp now()
Returns current time as Timestamp (UTC-based, nanosecond precision)
Definition tec_timestamp.hpp:172
Timestamp()
Default constructor — creates timestamp at epoch (count = 0)
Definition tec_timestamp.hpp:87
std::tm local_time() const
Returns broken-down local time as std::tm.
Definition tec_timestamp.hpp:136
Timestamp(count_t _count)
Construct from raw nanosecond count since epoch.
Definition tec_timestamp.hpp:92
std::string local_time_str() const
Returns ISO 8601 string in local time (with timezone offset)
Definition tec_timestamp.hpp:159
Timestamp(duration_t d)
Construct from std::chrono::nanoseconds duration.
Definition tec_timestamp.hpp:97
std::chrono::time_point< system_clock_t, duration_t > time_point_t
std::chrono time_point type with nanosecond precision
Definition tec_timestamp.hpp:67
count_t count
Nanoseconds since Unix epoch (1970-01-01T00:00:00Z).
Definition tec_timestamp.hpp:80
std::tm utc_time() const
Returns broken-down UTC time as std::tm.
Definition tec_timestamp.hpp:122
std::chrono::system_clock system_clock_t
Clock type used as the basis for time_point conversion.
Definition tec_timestamp.hpp:64
Common definitions and utilities for the tec namespace.