49#define TIME_T_MIN ((time_t) ((time_t)0 < (time_t) -1 ? (time_t) 0 \
50 : (time_t) (~0ULL << (sizeof (time_t) * CHAR_BIT - 1))))
53#define TIME_T_MAX ((time_t) (~ (time_t) 0 - TIME_T_MIN))
62#define WS_MSECS_PER_SEC (1000)
63#define WS_USECS_PER_SEC (1000*1000)
64#define WS_NSECS_PER_SEC (1000*1000*1000)
66#define WS_NSECS_PER_MSEC (WS_NSECS_PER_SEC/WS_MSECS_PER_SEC)
67#define WS_NSECS_PER_USEC (WS_NSECS_PER_SEC/WS_USECS_PER_SEC)
69#define WS_NSECS_PER_100NSEC (100)
70#define WS_100NSECS_PER_SEC (WS_NSECS_PER_SEC/WS_NSECS_PER_100NSEC)
75#define NSTIME_INIT_ZERO {0, 0}
78#define NSTIME_INIT_UNSET {0, INT_MAX}
84#define NSTIME_INIT_SECS_NSECS(secs, nsecs) {(secs) + ((nsecs) / WS_NSECS_PER_SEC), (nsecs) % WS_NSECS_PER_SEC}
90#define NSTIME_INIT_SECS_USECS(secs, usecs) {(secs) + ((usecs) / WS_USECS_PER_SEC), ((usecs) % WS_USECS_PER_SEC) * WS_NSECS_PER_USEC}
96#define NSTIME_INIT_SECS_MSECS(secs, msecs) {(secs) + ((msecs) / WS_MSECS_PER_SEC), ((msecs) % WS_MSECS_PER_SEC) * WS_NSECS_PER_MSEC}
99#define NSTIME_INIT_SECS(secs) {secs, 0}
102#define NSTIME_INIT_MAX {TIME_T_MAX, INT_MAX}
208#define nstime_add(sum, a) nstime_sum(sum, sum, a)
219#define nstime_subtract(sum, a) nstime_delta(sum, sum, a)
253static inline double nstime_to_msec(
const nstime_t *nstime)
255 return ((
double)nstime->secs*WS_MSECS_PER_SEC + (
double)nstime->nsecs/WS_NSECS_PER_MSEC);
266static inline double nstime_to_sec(
const nstime_t *nstime)
268 return ((
double)nstime->secs + (
double)nstime->nsecs/WS_NSECS_PER_SEC);
346#define NSTIME_ISO8601_BUFSIZE sizeof("YYYY-MM-DDTHH:MM:SS.123456789Z")
366#define NSTIME_UNIX_BUFSIZE (20+10+1)
408#define WS_TSPREC_MAX 9
416#define NUM_WS_TSPREC_VALS (WS_TSPREC_MAX + 1)
440#define nstime_round(a, prec) nstime_rounded(a, a, prec)
ws_tsprec_e
Timestamp precision levels.
Definition nstime.h:388
@ WS_TSPREC_USEC
Definition nstime.h:395
@ WS_TSPREC_100_NSEC
Definition nstime.h:396
@ WS_TSPREC_100_MSEC
Definition nstime.h:390
@ WS_TSPREC_100_USEC
Definition nstime.h:393
@ WS_TSPREC_NSEC
Definition nstime.h:398
@ WS_TSPREC_MSEC
Definition nstime.h:392
@ WS_TSPREC_10_MSEC
Definition nstime.h:391
@ WS_TSPREC_10_USEC
Definition nstime.h:394
@ WS_TSPREC_SEC
Definition nstime.h:389
@ WS_TSPREC_10_NSEC
Definition nstime.h:397
WS_DLL_PUBLIC void nstime_sum(nstime_t *sum, const nstime_t *a, const nstime_t *b)
Calculates the sum of two time values.
Definition nstime.c:146
WS_DLL_PUBLIC void nstime_set_unset(nstime_t *nstime)
Marks the given nstime_t as "unset".
Definition nstime.c:48
WS_DLL_PUBLIC size_t nstime_to_iso8601(char *buf, size_t buf_size, const nstime_t *nstime)
Converts an nstime_t to an ISO 8601 formatted string.
Definition nstime.c:654
WS_DLL_PUBLIC void nstime_delta(nstime_t *delta, const nstime_t *b, const nstime_t *a)
Calculates the time delta between two timestamps.
Definition nstime.c:80
WS_DLL_PUBLIC void nstime_set_zero(nstime_t *nstime)
Sets the given nstime_t to zero.
Definition nstime.c:26
WS_DLL_PUBLIC bool filetime_ns_to_nstime(nstime_t *nstime, uint64_t nsfiletime)
Converts a nanosecond-based FILETIME to nstime.
Definition nstime.c:312
WS_DLL_PUBLIC bool nstime_is_unset(const nstime_t *nstime)
Checks whether the given nstime_t is marked as "unset".
Definition nstime.c:55
iso8601_fmt_e
Selects the ISO 8601 datetime string format used for parsing or formatting timestamps.
Definition nstime.h:309
@ ISO8601_DATETIME
Definition nstime.h:310
@ ISO8601_DATETIME_AUTO
Definition nstime.h:312
@ ISO8601_DATETIME_BASIC
Definition nstime.h:311
WS_DLL_PUBLIC int nstime_cmp(const nstime_t *a, const nstime_t *b)
Compares two time values.
Definition nstime.c:195
WS_DLL_PUBLIC bool nstime_is_zero(const nstime_t *nstime)
Checks whether the given nstime_t is zero.
Definition nstime.c:33
WS_DLL_PUBLIC bool filetime_to_nstime(nstime_t *nstime, uint64_t filetime)
Converts a Windows FILETIME to nstime.
Definition nstime.c:288
WS_DLL_PUBLIC void nstime_copy(nstime_t *a, const nstime_t *b)
Copies one nstime_t value to another.
Definition nstime.c:69
WS_DLL_PUBLIC unsigned nstime_hash(const nstime_t *nstime)
Computes a hash value for a time value.
Definition nstime.c:232
WS_DLL_PUBLIC void nstime_rounded(nstime_t *a, const nstime_t *b, ws_tsprec_e prec)
Rounds a time value to the specified precision.
Definition nstime.c:239
WS_DLL_PUBLIC void nstime_to_unix(char *buf, size_t buf_size, const nstime_t *nstime)
Converts an nstime_t to a Unix timestamp string.
Definition nstime.c:705
WS_DLL_PUBLIC bool filetime_1sec_to_nstime(nstime_t *nstime, uint64_t filetime)
Converts a second-based FILETIME to nstime.
Definition nstime.c:333
WS_DLL_PUBLIC const char * iso8601_to_nstime(nstime_t *nstime, const char *ptr, iso8601_fmt_e format)
Parses an ISO 8601 formatted datetime string into an nstime_t.
Definition nstime.c:372
WS_DLL_PUBLIC bool nstime_is_negative(const nstime_t *nstime)
Checks whether the given nstime_t is negative.
Definition nstime.c:39
WS_DLL_PUBLIC const char * unix_epoch_to_nstime(nstime_t *nstime, const char *ptr)
Parses a Unix epoch timestamp string into an nstime_t.
Definition nstime.c:593