1 #include "artdaq-core/Utilities/TimeUtils.hh"
3 #define BOOST_TEST_MODULE TimeUtils_t
5 #include "cetlib/quiet_unit_test.hpp"
6 #include "cetlib_except/exception.h"
8 #define TRACE_NAME "TimeUtils_t"
11 BOOST_AUTO_TEST_SUITE(TimeUtils_test)
13 BOOST_AUTO_TEST_CASE(GetElapsedTime)
15 auto then = std::chrono::steady_clock::now();
16 auto now = then + std::chrono::seconds(1);
23 BOOST_AUTO_TEST_CASE(UnixTime)
27 gettimeofday(&tv,
nullptr);
31 TLOG(TLVL_INFO) <<
"time_t to string: " << timeString;
33 TLOG(TLVL_INFO) <<
"time_t to seconds: " << timeDouble;
36 TLOG(TLVL_INFO) <<
"timeval to string: " << valString;
38 TLOG(TLVL_INFO) <<
"timeval to seconds: " << valDouble;
41 TLOG(TLVL_INFO) <<
"timespec to string: " << specString;
43 TLOG(TLVL_INFO) <<
"timespec to seconds: " << specDouble;
45 BOOST_REQUIRE_EQUAL(timeDouble, std::floor(valDouble));
46 BOOST_REQUIRE_EQUAL(timeDouble, std::floor(specDouble));
49 BOOST_AUTO_TEST_CASE(GetTimeOfDayUS)
53 BOOST_REQUIRE_EQUAL(now / 1000000, ts.tv_sec);
56 BOOST_AUTO_TEST_SUITE_END()
constexpr size_t GetElapsedTimeMilliseconds(std::chrono::steady_clock::time_point then, std::chrono::steady_clock::time_point now=std::chrono::steady_clock::now())
Gets the number of milliseconds in the given time interval
constexpr size_t GetElapsedTimeMicroseconds(std::chrono::steady_clock::time_point then, std::chrono::steady_clock::time_point now=std::chrono::steady_clock::now())
Gets the number of microseconds in the given time interval
struct timespec get_realtime_clock()
Get the current time of day as a pair of seconds and nanoseconds (from clock_gettime(CLOCK_REALTIME, ...) system call)
double convertUnixTimeToSeconds(time_t inputUnixTime)
Converts a Unix time to double.
constexpr double GetElapsedTime(std::chrono::steady_clock::time_point then, std::chrono::steady_clock::time_point now=std::chrono::steady_clock::now())
Get the number of seconds in the given interval
std::string convertUnixTimeToString(time_t inputUnixTime)
Converts a Unix time to its string representation, in UTC.
uint64_t gettimeofday_us()
Get the current time of day in microseconds (from gettimeofday system call)