lokinet/llarp/time.cpp

31 lines
593 B
C++
Raw Normal View History

2018-01-29 14:27:24 +00:00
#include <llarp/time.h>
2018-02-01 13:21:00 +00:00
#include <chrono>
2018-01-19 16:51:27 +00:00
namespace llarp
{
2018-06-16 12:34:22 +00:00
typedef std::chrono::steady_clock clock_t;
2018-01-19 16:51:27 +00:00
template < typename Res, typename IntType >
static IntType
time_since_epoch()
{
return std::chrono::duration_cast< Res >(
llarp::clock_t::now().time_since_epoch())
.count();
}
2018-02-01 13:21:00 +00:00
} // namespace llarp
2018-01-19 16:51:27 +00:00
extern "C" {
llarp_time_t
llarp_time_now_ms()
{
return llarp::time_since_epoch< std::chrono::milliseconds, llarp_time_t >();
2018-01-29 14:27:24 +00:00
}
llarp_seconds_t
llarp_time_now_sec()
{
return llarp::time_since_epoch< std::chrono::seconds, llarp_seconds_t >();
2018-01-29 14:27:24 +00:00
}
2018-01-19 16:51:27 +00:00
}