2018-05-17 07:18:45 +02:00
|
|
|
#include "time.h"
|
2018-08-03 08:49:45 +02:00
|
|
|
#include <chrono>
|
2018-05-17 07:18:45 +02:00
|
|
|
|
2018-08-03 08:49:45 +02:00
|
|
|
using std::chrono::system_clock;
|
|
|
|
using std::chrono::duration_cast;
|
|
|
|
using std::chrono::seconds;
|
|
|
|
using std::chrono::nanoseconds;
|
2016-02-13 02:46:00 +01:00
|
|
|
|
2018-05-17 15:37:47 +02:00
|
|
|
namespace cpputils {
|
|
|
|
namespace time {
|
|
|
|
|
2018-08-03 08:49:45 +02:00
|
|
|
struct timespec now() {
|
|
|
|
auto now = system_clock::now().time_since_epoch();
|
2018-10-14 22:26:30 +02:00
|
|
|
struct timespec spec{};
|
2018-08-03 08:49:45 +02:00
|
|
|
spec.tv_sec = duration_cast<seconds>(now).count();
|
|
|
|
spec.tv_nsec = duration_cast<nanoseconds>(now).count() % 1000000000;
|
2018-05-17 15:37:47 +02:00
|
|
|
return spec;
|
|
|
|
}
|
|
|
|
|
2016-02-13 02:46:00 +01:00
|
|
|
}
|
2018-05-17 07:18:45 +02:00
|
|
|
}
|