diff --git a/include/zinnia/time.h b/include/zinnia/time.h index e4ebd31..621b83a 100644 --- a/include/zinnia/time.h +++ b/include/zinnia/time.h @@ -2,6 +2,16 @@ #include -struct timespec time_from_sec(uint64_t sec); -struct timespec time_from_nano(uint64_t nsec); -struct timespec time_from_milli(uint64_t msec); +typedef struct __timespec timespec_t; + +static inline timespec_t time_from_sec(uint64_t sec) { + return (timespec_t){.tv_sec = sec, .tv_nsec = 0}; +} + +static inline timespec_t time_from_nano(uint64_t nsec) { + return (timespec_t){.tv_sec = nsec / 1'000'000'000, .tv_nsec = nsec % 1'000'000'000}; +} + +static inline timespec_t time_from_milli(uint64_t msec) { + return (timespec_t){.tv_sec = msec / 1'000, .tv_nsec = (msec % 1'000) * 1'000'000}; +}