12 #ifndef flatlogs_timespecX_hpp
13 #define flatlogs_timespecX_hpp
61 if(ts.tv_sec < 0 || ts.tv_sec > 4294967295)
93 template<clock
id_t clk_
id=CLOCK_REALTIME>
97 clock_gettime(clk_id, &ts);
114 if(gmtime_r(&t0, &uttime) == 0)
116 std::cerr <<
"Error getting UT time (gmtime_r returned 0). At: " << __FILE__ <<
" " << __LINE__ <<
"\n";
122 snprintf(buffer,
sizeof(buffer),
"%04i%02i%02i%02i%02i%02i%09i", uttime.tm_year+1900, uttime.tm_mon+1, uttime.tm_mday, uttime.tm_hour, uttime.tm_min, uttime.tm_sec,
static_cast<int>(
time_ns));
157 gmtime_r( &tt, &bdt);
161 strftime(tstr1, 25,
"%FT%H:%M:%S", &bdt);
165 snprintf(tstr2, 11,
".%09i",
static_cast<int>(
time_ns));
167 return std::string(tstr1) + std::string(tstr2);
174 gmtime_r( &tt, &bdt);
178 strftime(tstr1, 25,
"%FT%H:%M", &bdt);
180 return std::string(tstr1);
197 gmtime_r( &tt, &bdt);
201 strftime(tstr1,
sizeof(tstr1),
"%S", &bdt);
205 snprintf(tstr2,
sizeof(tstr2),
".%02i",
static_cast<int>(
time_ns));
207 return std::string(tstr1) + std::string(tstr2);
220 gmtime_r( &tt, &bdt);
236 } __attribute__((packed));
309 return ( tsL < tsR || tsL == tsR );
327 return ( tsL > tsR || tsL == tsR );
336 ts1.
time_s = std::floor(means);
337 ts1.
time_ns = std::round(meanns);
339 if( means != floor(means) )
377 template<clock
id_t clk_
id=CLOCK_REALTIME>
void clock_gettimeX(timespecX &tsX)
Fill in a timespecX with the current time.
void timespecFromX(timespec &ts, const timespecX &tsX)
Convert a timespecX to a native timespec.
uint32_t secT
The type used for seconds.
Type definitions for the flatlogs format.
bool operator<=(timespecX const &tsL, timespecX const &tsR)
TimespecX comparison operator <= (see caveats)
timespecX meanTimespecX(timespecX ts1, timespecX ts2)
bool operator>=(timespecX const &tsL, timespecX const &tsR)
TimespecX comparison operator >= (see caveats)
bool operator==(timespecX const &tsL, timespecX const &tsR)
TimespecX comparison operator == (see caveats)
bool operator>(timespecX const &tsL, timespecX const &tsR)
TimespecX comparison operator > (see caveats)
uint32_t nanosecT
The type used for nanoseconds.
bool operator<(timespecX const &tsL, timespecX const &tsR)
TimespecX comparison operator < (see caveats)
A fixed-width timespec structure.
std::string ISO8601DateTimeStr2MinX()
std::string timeStamp()
Get the filname timestamp for this timespecX.
timespecX()
Default c'tor.
int timeStamp(std::string &tstamp)
Get the filename timestamp for this timespecX.
nanosecT time_ns
Nanoseconds.
timespecX & operator=(const timespec &ts)
Convert a native timespec to a timespecX.
secT time_s
Time since the Unix epoch.
int minute()
Get the minute from a timespecX.
std::string secondStrX()
Get a date-time string with just the second for timespecX.
timespecX(secT s, nanosecT ns)
Construct with time values.
std::string ISO8601DateTimeStrX()
Get a date-time string in ISO 8601 format for timespecX.
timespecX(const timespec &ts)
Construct from timespec.
void gettime()
Fill the the timespecX with the current time.
timespec getTimespec()
Get a native timespec from this custom one.
double asDouble()
Get the time as a double from a timespecX.