X-Git-Url: https://git.tokkee.org/?p=sysdb.git;a=blobdiff_plain;f=src%2Finclude%2Fcore%2Ftime.h;h=c48a2e1329b6bb8371507fa382dcf90601591a18;hp=30e920b6a0905de566874e3a9afddceaee4259cb;hb=f78d30d42f9fe3b58f1c2132cafe4c8687b8bd46;hpb=fa5c130fbd0c75f3c47f1b28feb8d76a4791a93e diff --git a/src/include/core/time.h b/src/include/core/time.h index 30e920b..c48a2e1 100644 --- a/src/include/core/time.h +++ b/src/include/core/time.h @@ -41,7 +41,7 @@ extern "C" { * The time, in nano-seconds, since the epoch. */ typedef uint64_t sdb_time_t; -#define PRIscTIME PRIu64 +#define PRIsdbTIME PRIu64 #define SECS_TO_SDB_TIME(s) ((sdb_time_t)(s) * (sdb_time_t)1000000000) #define SDB_TIME_TO_SECS(t) ((t) / (sdb_time_t)1000000000) @@ -54,6 +54,19 @@ typedef uint64_t sdb_time_t; #define TIMESPEC_TO_SDB_TIME(ts) (SECS_TO_SDB_TIME((ts).tv_sec) \ + NSECS_TO_SDB_TIME((ts).tv_nsec)) +/* + * Interval constants: + * Each constant specifies the time interval, in nano-seconds, of the named + * time-frame. Year, month, and day are approximations which do not work well + * for very large time intervals. + */ +extern const sdb_time_t SDB_INTERVAL_YEAR; +extern const sdb_time_t SDB_INTERVAL_MONTH; +extern const sdb_time_t SDB_INTERVAL_DAY; +extern const sdb_time_t SDB_INTERVAL_HOUR; +extern const sdb_time_t SDB_INTERVAL_MINUTE; +extern const sdb_time_t SDB_INTERVAL_SECOND; + sdb_time_t sdb_gettime(void); @@ -61,7 +74,24 @@ int sdb_sleep(sdb_time_t reg, sdb_time_t *rem); size_t -sdb_strftime(char *s, size_t len, const char *format, sdb_time_t); +sdb_strftime(char *s, size_t len, const char *format, sdb_time_t) + __attribute__((format(strftime, 3, 0))); + +size_t +sdb_strfinterval(char *s, size_t len, sdb_time_t interval); + +/* + * sdb_strpunit: + * Parse the specified string as a time unit. + * "Y" (year), "M" (month), "D" (day), "h" (hour), "m" (minute), "s" (second), + * "ms" (milli-second), "us" (micro-second), "ns" (nano-second). + * + * Returns: + * - the time interval corresponding to the specified unit on success + * - 0 else + */ +sdb_time_t +sdb_strpunit(const char *s); #ifdef __cplusplus } /* extern "C" */