21#if !defined(__RLIB_H_INCLUDE_GUARD__) && !defined(RLIB_COMPILATION)
22#error "#include <rlib.h> only please."
53#define R_CLOCK_TIME_IS_VALID(time) (((RClockTime)(time)) != R_CLOCK_TIME_NONE)
56#define R_NSECOND RINT64_CONSTANT (1)
58#define R_USECOND RINT64_CONSTANT (1000)
60#define R_MSECOND RINT64_CONSTANT (1000000)
62#define R_SECOND RINT64_CONSTANT (1000000000)
64#define R_MSEC_PER_SEC 1000
66#define R_USEC_PER_SEC 1000000
68#define R_NSEC_PER_SEC 1000000000
70#define R_TIME_AS_HOURS(time) ((time) / (R_SECOND * 60 * 60))
72#define R_TIME_AS_MINUTES(time) ((time) / (R_SECOND * 60))
74#define R_TIME_AS_SECONDS(time) ((time) / R_SECOND)
76#define R_TIME_AS_MSECONDS(time) ((time) / R_MSECOND)
78#define R_TIME_AS_USECONDS(time) ((time) / R_USECOND)
80#define R_TIME_AS_NSECONDS(time) ((time) / R_NSECOND)
83#define R_CLOCK_DIFF(s, e) (RClockTimeDiff)((e) - (s))
86#define R_TIMESPEC_TO_TIME(ts) (RClockTime)((ts).tv_sec * R_SECOND + (ts).tv_nsec * R_NSECOND)
88#define R_TIME_TO_TIMESPEC(t,ts) \
90 (ts).tv_sec = (rlong) ( (t) / R_SECOND); \
91 (ts).tv_nsec = (rlong) (((t) % R_SECOND) / R_NSECOND); \
94#define R_TIME_TIMESPEC_INIT(t) { (rlong) ( (t) / R_SECOND), \
95 (rlong) (((t) % R_SECOND) / R_NSECOND) }
98#define R_TIMEVAL_TO_TIME(tv) (RClockTime)((tv).tv_sec * R_SECOND + (tv).tv_usec * R_USECOND)
100#define R_TIME_TO_TIMEVAL(t,tv) \
102 (tv).tv_sec = (rlong) ( (t) / R_SECOND); \
103 (tv).tv_usec = (rlong) (((t) % R_SECOND) / R_USECOND); \
106#define R_TIME_TIMEVAL_INIT(t) { (rlong) ( (t) / R_SECOND), \
107 (rlong) (((t) % R_SECOND) / R_USECOND) }
116#define R_TIME_FORMAT "u:%02u:%02u.%09u"
118#define R_TIME_ARGS(t) \
119 R_CLOCK_TIME_IS_VALID (t) ? (ruint) R_TIME_AS_HOURS (t) : 99, \
120 R_CLOCK_TIME_IS_VALID (t) ? (ruint) R_TIME_AS_MINUTES (t) % 60 : 99, \
121 R_CLOCK_TIME_IS_VALID (t) ? (ruint) R_TIME_AS_SECONDS (t) % 60 : 99, \
122 R_CLOCK_TIME_IS_VALID (t) ? (ruint) ((t) % R_SECOND) : 999999999
174#define r_time_get_time_since_epoch() r_time_get_unix_time ()
#define R_API
Public-API decoration: resolves to R_API_EXPORT while building rlib and R_API_IMPORT for consumers.
Definition rmacros.h:115
#define R_BEGIN_DECLS
Open an extern "C" block under C++ (no-op in C).
Definition rmacros.h:196
RClockTime r_time_get_ts_monotonic(void)
Read the monotonic timestamp (CLOCK_MONOTONIC); strictly non-decreasing across calls in a single boot...
RClockTime r_time_get_ts_raw(void)
Read the raw monotonic timestamp (CLOCK_MONOTONIC_RAW on Linux); not subject to NTP slewing.
rboolean r_time_parse_unix_time(ruint64 time, ruint16 *year, ruint8 *month, ruint8 *day, ruint8 *hour, ruint8 *minute, ruint8 *second)
Split a Unix timestamp into broken-down date components.
ruint64 r_time_create_unix_time(ruint16 year, ruint8 month, ruint8 day, ruint8 hour, ruint8 minute, ruint8 second)
Convert a broken-down date to a Unix timestamp (seconds since 1970-01-01 UTC).
ruint16 r_time_leap_years(ruint16 from, ruint16 to)
Count leap years in the half-open range [from, to), with from clamped up to 1753.
ruint64 r_time_get_uptime(void)
Return system uptime in seconds.
RClockTime r_time_get_ts_wallclock(void)
Read the wall-clock real-time timestamp (CLOCK_REALTIME).
rint8 r_time_days_in_month(ruint16 year, ruint8 month)
Days in month (1-12) of year, accounting for leap years; -1 if month is out of range or year is befor...
rboolean r_time_is_leap_year(ruint16 year)
TRUE if year is a Gregorian leap year. Years before 1753 always return FALSE.
ruint64 r_time_get_unix_time(void)
Return the current Unix timestamp (seconds since 1970-01-01 UTC).
int rboolean
Boolean type (typedef'd to int).
Definition rtypes.h:59
signed char rint8
Signed 8-bit integer.
Definition rtypes.h:185
unsigned char ruint8
Unsigned 8-bit integer.
Definition rtypes.h:190
unsigned long ruint64
Unsigned 64-bit integer.
Definition rtypes.h:193
unsigned short ruint16
Unsigned 16-bit integer.
Definition rtypes.h:191
ruint64 RClockTime
Unsigned 64-bit timestamp / duration, in nanoseconds.
Definition rtypes.h:353
Foundational type aliases used by every rlib header.