90# define ANJ_TIME_US_MAX INT64_MAX
98# define ANJ_TIME_DURATION_AS_STRING_MAX_LEN (sizeof("-9223372036854775808"))
266 const int32_t factor) {
289 const double factor) {
312 const int32_t divisor) {
328 return lhs.
us == rhs.
us;
337 return lhs.
us < rhs.
us;
346 return lhs.
us > rhs.
us;
355 return lhs.
us <= rhs.
us;
364 return lhs.
us >= rhs.
us;
410# define ANJ_TIME_DURATION_AS_STRING(duration, unit) \
411 (_anj_time_duration_as_string_impl( \
414 &(char[ANJ_TIME_DURATION_AS_STRING_MAX_LEN]){ "" }))
589# define ANJ_TIME_MONOTONIC_AS_STRING(time, unit) \
590 (_anj_time_duration_as_string_impl( \
591 time.since_monotonic_epoch, \
593 &(char[ANJ_TIME_DURATION_AS_STRING_MAX_LEN]){ "" }))
760# define ANJ_TIME_REAL_AS_STRING(time, unit) \
761 (_anj_time_duration_as_string_impl( \
762 time.since_real_epoch, \
764 &(char[ANJ_TIME_DURATION_AS_STRING_MAX_LEN]){ "" }))
Global configuration validation header for Anjay Lite.
Relative duration of time.
Definition time.h:106
int64_t us
Number of microseconds.
Definition time.h:110
Absolute monotonic time (time since boot).
Definition time.h:119
anj_time_duration_t since_monotonic_epoch
Duration since an unspecified monotonic epoch (e.g., boot).
Definition time.h:123
Absolute real (calendar) time.
Definition time.h:131
anj_time_duration_t since_real_epoch
Duration since January 1, 1970, 00:00:00 UTC.
Definition time.h:135
const anj_time_duration_t ANJ_TIME_DURATION_ZERO
Zero duration (0 microseconds).
int64_t anj_time_duration_to_scalar(anj_time_duration_t duration, anj_time_unit_t unit)
Converts a duration to an integer scalar in the given unit.
static anj_time_duration_t anj_time_duration_add(const anj_time_duration_t lhs, const anj_time_duration_t rhs)
Adds two durations.
Definition time.h:223
static bool anj_time_real_leq(const anj_time_real_t lhs, const anj_time_real_t rhs)
Less-or-equal comparison for real timestamps.
Definition time.h:737
static int64_t anj_time_monotonic_to_scalar(const anj_time_monotonic_t time, const anj_time_unit_t unit)
Converts a monotonic timestamp to an integer scalar in the given unit.
Definition time.h:486
static double anj_time_monotonic_to_fscalar(const anj_time_monotonic_t time, const anj_time_unit_t unit)
Converts a monotonic timestamp to a floating-point scalar.
Definition time.h:500
static anj_time_duration_t anj_time_real_diff(const anj_time_real_t end, const anj_time_real_t start)
Computes the difference between two real timestamps.
Definition time.h:713
anj_time_unit_t
Time unit of a scalar value.
Definition time.h:53
@ ANJ_TIME_UNIT_US
Microseconds (1/1000 milliseconds).
Definition time.h:82
@ ANJ_TIME_UNIT_S
Seconds (1000 milliseconds).
Definition time.h:72
@ ANJ_TIME_UNIT_HOUR
Hours (60 minutes).
Definition time.h:62
@ ANJ_TIME_UNIT_MS
Milliseconds (1000 microseconds).
Definition time.h:77
@ ANJ_TIME_UNIT_MIN
Minutes (60 seconds).
Definition time.h:67
@ ANJ_TIME_UNIT_DAY
Days (24 hours).
Definition time.h:57
static bool anj_time_duration_leq(const anj_time_duration_t lhs, const anj_time_duration_t rhs)
Less-or-equal comparison for durations.
Definition time.h:349
static anj_time_monotonic_t anj_time_monotonic_fnew(const double scalar, const anj_time_unit_t unit)
Creates a monotonic timestamp from a floating-point scalar and unit.
Definition time.h:462
static anj_time_monotonic_t anj_time_monotonic_new(const int64_t scalar, const anj_time_unit_t unit)
Creates a monotonic timestamp from an integer scalar and unit.
Definition time.h:449
const anj_time_monotonic_t ANJ_TIME_MONOTONIC_ZERO
Monotonic time set to 0 (monotonic epoch).
#define ANJ_TIME_US_MAX
Maximum value for a duration in microseconds.
Definition time.h:90
static bool anj_time_real_eq(const anj_time_real_t lhs, const anj_time_real_t rhs)
Equality comparison for real timestamps.
Definition time.h:731
static anj_time_duration_t anj_time_duration_sub(const anj_time_duration_t lhs, const anj_time_duration_t rhs)
Subtracts two durations.
Definition time.h:244
const anj_time_duration_t ANJ_TIME_DURATION_INVALID
Sentinel duration representing “infinity”.
static anj_time_duration_t anj_time_monotonic_diff(const anj_time_monotonic_t end, const anj_time_monotonic_t start)
Computes the difference between two monotonic timestamps.
Definition time.h:542
anj_time_duration_t anj_time_duration_fnew(double scalar, anj_time_unit_t unit)
Creates a duration from a floating-point scalar in the given unit.
static anj_time_real_t anj_time_real_sub(const anj_time_real_t start, const anj_time_duration_t duration)
Subtracts a relative duration from a real timestamp.
Definition time.h:699
static bool anj_time_duration_lt(const anj_time_duration_t lhs, const anj_time_duration_t rhs)
Less-than comparison for durations.
Definition time.h:331
static anj_time_real_t anj_time_real_new(const int64_t scalar, const anj_time_unit_t unit)
Creates a real timestamp from an integer scalar and unit.
Definition time.h:626
static bool anj_time_duration_gt(const anj_time_duration_t lhs, const anj_time_duration_t rhs)
Greater-than comparison for durations.
Definition time.h:340
double anj_time_duration_to_fscalar(anj_time_duration_t duration, anj_time_unit_t unit)
Converts a duration to a floating-point scalar in the given unit.
static bool anj_time_monotonic_leq(const anj_time_monotonic_t lhs, const anj_time_monotonic_t rhs)
Less-or-equal comparison for monotonic timestamps.
Definition time.h:567
static bool anj_time_monotonic_eq(const anj_time_monotonic_t lhs, const anj_time_monotonic_t rhs)
Equality comparison for monotonic timestamps.
Definition time.h:561
static anj_time_real_t anj_time_real_add(const anj_time_real_t start, const anj_time_duration_t duration)
Adds a relative duration to a real timestamp.
Definition time.h:685
static anj_time_duration_t anj_time_real_to_duration(const anj_time_real_t time)
Converts a real timestamp to a duration since the Unix epoch.
Definition time.h:615
static bool anj_time_real_gt(const anj_time_real_t lhs, const anj_time_real_t rhs)
Greater-than comparison for real timestamps.
Definition time.h:725
const char * _anj_time_duration_as_string_impl(anj_time_duration_t duration, anj_time_unit_t unit, char(*buffer)[ANJ_TIME_DURATION_AS_STRING_MAX_LEN])
Internal helper that renders a duration to a string buffer.
static bool anj_time_monotonic_geq(const anj_time_monotonic_t lhs, const anj_time_monotonic_t rhs)
Greater-or-equal comparison for monotonic timestamps.
Definition time.h:573
static bool anj_time_real_geq(const anj_time_real_t lhs, const anj_time_real_t rhs)
Greater-or-equal comparison for real timestamps.
Definition time.h:743
static bool anj_time_real_is_valid(const anj_time_real_t time)
Checks whether a real timestamp is valid.
Definition time.h:673
const anj_time_real_t ANJ_TIME_REAL_ZERO
Real time set to 0 (Unix epoch).
static anj_time_monotonic_t anj_time_monotonic_add(const anj_time_monotonic_t start, const anj_time_duration_t duration)
Adds a relative duration to a monotonic timestamp.
Definition time.h:514
static anj_time_monotonic_t anj_time_monotonic_from_duration(const anj_time_duration_t duration)
Constructs a monotonic timestamp from a duration since the monotonic epoch.
Definition time.h:424
const anj_time_real_t ANJ_TIME_REAL_INVALID
Sentinel real time representing “infinity”.
static int64_t anj_time_real_to_scalar(const anj_time_real_t time, const anj_time_unit_t unit)
Converts a real timestamp to an integer scalar in the given unit.
Definition time.h:650
#define ANJ_TIME_DURATION_AS_STRING_MAX_LEN
Maximum length for buffers created by ANJ_TIME_DURATION_AS_STRING and related macros.
Definition time.h:98
static double anj_time_real_to_fscalar(const anj_time_real_t time, const anj_time_unit_t unit)
Converts a real timestamp to a floating-point scalar.
Definition time.h:662
static anj_time_duration_t anj_time_monotonic_to_duration(const anj_time_monotonic_t time)
Converts a monotonic timestamp to a duration since the monotonic epoch.
Definition time.h:437
const anj_time_monotonic_t ANJ_TIME_MONOTONIC_INVALID
Sentinel monotonic time representing “infinity”.
static bool anj_time_duration_geq(const anj_time_duration_t lhs, const anj_time_duration_t rhs)
Greater-or-equal comparison for durations.
Definition time.h:358
static anj_time_duration_t anj_time_duration_mul(const anj_time_duration_t duration, const int32_t factor)
Multiplies a duration by an integer factor.
Definition time.h:265
static bool anj_time_duration_is_valid(anj_time_duration_t duration)
Checks whether a duration value is valid.
Definition time.h:205
anj_time_duration_t anj_time_duration_new(int64_t scalar, anj_time_unit_t unit)
Creates a duration from an integer scalar in the given unit.
static anj_time_duration_t anj_time_duration_fmul(const anj_time_duration_t duration, const double factor)
Multiplies a duration by a floating-point factor.
Definition time.h:288
static bool anj_time_real_lt(const anj_time_real_t lhs, const anj_time_real_t rhs)
Less-than comparison for real timestamps.
Definition time.h:719
static anj_time_duration_t anj_time_duration_div(const anj_time_duration_t duration, const int32_t divisor)
Divides a duration by an integer divisor.
Definition time.h:311
static anj_time_monotonic_t anj_time_monotonic_sub(const anj_time_monotonic_t start, const anj_time_duration_t duration)
Subtracts a relative duration from a monotonic timestamp.
Definition time.h:528
static bool anj_time_duration_eq(const anj_time_duration_t lhs, const anj_time_duration_t rhs)
Equality comparison for durations.
Definition time.h:322
static bool anj_time_monotonic_gt(const anj_time_monotonic_t lhs, const anj_time_monotonic_t rhs)
Greater-than comparison for monotonic timestamps.
Definition time.h:555
static bool anj_time_monotonic_is_valid(const anj_time_monotonic_t time)
Checks whether a monotonic timestamp is valid.
Definition time.h:474
static anj_time_real_t anj_time_real_from_duration(const anj_time_duration_t duration)
Constructs a real (wall-clock) timestamp from a duration since Unix epoch.
Definition time.h:603
static bool anj_time_monotonic_lt(const anj_time_monotonic_t lhs, const anj_time_monotonic_t rhs)
Less-than comparison for monotonic timestamps.
Definition time.h:549
static anj_time_real_t anj_time_real_fnew(const double scalar, const anj_time_unit_t unit)
Creates a real timestamp from a floating-point scalar and unit.
Definition time.h:638