2018-01-29 14:27:24 +00:00
|
|
|
#include <llarp/time.h>
|
2018-10-02 15:32:07 +00:00
|
|
|
#include <time.h>
|
2018-09-29 08:16:54 +00:00
|
|
|
#include <sys/time.h>
|
2018-01-19 16:51:27 +00:00
|
|
|
|
2018-09-29 08:16:54 +00:00
|
|
|
// these _should_ be 32-bit safe...
|
2018-05-22 15:54:19 +00:00
|
|
|
llarp_time_t
|
|
|
|
llarp_time_now_ms()
|
|
|
|
{
|
2018-09-29 08:16:54 +00:00
|
|
|
struct timeval tv;
|
2018-10-02 15:29:37 +00:00
|
|
|
struct timezone z;
|
|
|
|
z.tz_minuteswest = 0;
|
2018-10-03 10:33:28 +00:00
|
|
|
time_t t = time(nullptr);
|
|
|
|
z.tz_dsttime = gmtime(&t)->tm_isdst;
|
2018-10-02 15:29:37 +00:00
|
|
|
gettimeofday(&tv, &z);
|
2018-09-29 08:16:54 +00:00
|
|
|
llarp_time_t timeNow =
|
|
|
|
(llarp_time_t)(tv.tv_sec) * 1000 + (llarp_time_t)(tv.tv_usec) / 1000;
|
|
|
|
return timeNow;
|
2018-01-29 14:27:24 +00:00
|
|
|
}
|
|
|
|
|
2018-05-22 15:54:19 +00:00
|
|
|
llarp_seconds_t
|
|
|
|
llarp_time_now_sec()
|
|
|
|
{
|
2018-09-29 08:16:54 +00:00
|
|
|
struct timeval tv;
|
2018-10-02 15:29:37 +00:00
|
|
|
struct timezone z;
|
|
|
|
z.tz_minuteswest = 0;
|
2018-10-03 10:33:28 +00:00
|
|
|
time_t t = time(nullptr);
|
|
|
|
z.tz_dsttime = gmtime(&t)->tm_isdst;
|
2018-10-02 15:29:37 +00:00
|
|
|
gettimeofday(&tv, &z);
|
2018-09-29 08:16:54 +00:00
|
|
|
llarp_time_t timeNow = tv.tv_sec;
|
|
|
|
return timeNow;
|
2018-01-29 14:27:24 +00:00
|
|
|
}
|