Anjay Lite
Loading...
Searching...
No Matches
time.h File Reference

Strongly-typed time utilities used across Anjay Lite. More...

#include <anj/init.h>
#include <inttypes.h>
#include <math.h>
#include <stdbool.h>
#include <stddef.h>
#include <stdint.h>

Go to the source code of this file.

Data Structures

struct  anj_time_duration_t
 Relative duration of time. More...
 
struct  anj_time_monotonic_t
 Absolute monotonic time (time since boot). More...
 
struct  anj_time_real_t
 Absolute real (calendar) time. More...
 

Macros

#define ANJ_TIME_US_MAX   INT64_MAX
 Maximum value for a duration in microseconds.
 
#define ANJ_TIME_DURATION_AS_STRING_MAX_LEN   (sizeof("-9223372036854775808"))
 Maximum length for buffers created by ANJ_TIME_DURATION_AS_STRING and related macros.
 
#define ANJ_TIME_DURATION_AS_STRING(duration, unit)
 Formats a duration as a string in the given unit.
 
#define ANJ_TIME_MONOTONIC_AS_STRING(time, unit)
 Formats a monotonic timestamp as a duration string in the given unit.
 
#define ANJ_TIME_REAL_AS_STRING(time, unit)
 Formats a real timestamp as a duration string in the given unit.
 

Enumerations

enum  anj_time_unit_t {
  ANJ_TIME_UNIT_DAY , ANJ_TIME_UNIT_HOUR , ANJ_TIME_UNIT_MIN , ANJ_TIME_UNIT_S ,
  ANJ_TIME_UNIT_MS , ANJ_TIME_UNIT_US
}
 Time unit of a scalar value. More...
 

Functions

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.
 
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.
 
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.
 
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_duration_is_valid (anj_time_duration_t duration)
 Checks whether a duration value is valid.
 
static anj_time_duration_t anj_time_duration_add (const anj_time_duration_t lhs, const anj_time_duration_t rhs)
 Adds two durations.
 
static anj_time_duration_t anj_time_duration_sub (const anj_time_duration_t lhs, const anj_time_duration_t rhs)
 Subtracts two durations.
 
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.
 
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.
 
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.
 
static bool anj_time_duration_eq (const anj_time_duration_t lhs, const anj_time_duration_t rhs)
 Equality comparison for durations.
 
static bool anj_time_duration_lt (const anj_time_duration_t lhs, const anj_time_duration_t rhs)
 Less-than comparison for durations.
 
static bool anj_time_duration_gt (const anj_time_duration_t lhs, const anj_time_duration_t rhs)
 Greater-than comparison for durations.
 
static bool anj_time_duration_leq (const anj_time_duration_t lhs, const anj_time_duration_t rhs)
 Less-or-equal comparison for durations.
 
static bool anj_time_duration_geq (const anj_time_duration_t lhs, const anj_time_duration_t rhs)
 Greater-or-equal comparison for durations.
 
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 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.
 
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.
 
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.
 
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.
 
static bool anj_time_monotonic_is_valid (const anj_time_monotonic_t time)
 Checks whether a monotonic timestamp is valid.
 
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.
 
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.
 
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.
 
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.
 
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.
 
static bool anj_time_monotonic_lt (const anj_time_monotonic_t lhs, const anj_time_monotonic_t rhs)
 Less-than comparison for monotonic timestamps.
 
static bool anj_time_monotonic_gt (const anj_time_monotonic_t lhs, const anj_time_monotonic_t rhs)
 Greater-than comparison for monotonic timestamps.
 
static bool anj_time_monotonic_eq (const anj_time_monotonic_t lhs, const anj_time_monotonic_t rhs)
 Equality comparison for monotonic timestamps.
 
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.
 
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.
 
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.
 
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.
 
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.
 
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.
 
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.
 
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.
 
static bool anj_time_real_is_valid (const anj_time_real_t time)
 Checks whether a real timestamp is valid.
 
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.
 
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.
 
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.
 
static bool anj_time_real_lt (const anj_time_real_t lhs, const anj_time_real_t rhs)
 Less-than comparison for real timestamps.
 
static bool anj_time_real_gt (const anj_time_real_t lhs, const anj_time_real_t rhs)
 Greater-than comparison for real timestamps.
 
static bool anj_time_real_eq (const anj_time_real_t lhs, const anj_time_real_t rhs)
 Equality comparison for real timestamps.
 
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.
 
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.
 

Variables

const anj_time_duration_t ANJ_TIME_DURATION_ZERO
 Zero duration (0 microseconds).
 
const anj_time_real_t ANJ_TIME_REAL_ZERO
 Real time set to 0 (Unix epoch).
 
const anj_time_monotonic_t ANJ_TIME_MONOTONIC_ZERO
 Monotonic time set to 0 (monotonic epoch).
 
const anj_time_duration_t ANJ_TIME_DURATION_INVALID
 Sentinel duration representing “infinity”.
 
const anj_time_real_t ANJ_TIME_REAL_INVALID
 Sentinel real time representing “infinity”.
 
const anj_time_monotonic_t ANJ_TIME_MONOTONIC_INVALID
 Sentinel monotonic time representing “infinity”.
 

Detailed Description

Strongly-typed time utilities used across Anjay Lite.

The module provides:

Note
All durations are represented internally as signed 64-bit microseconds. Arithmetic operations do not check for overflow. Use with values that fit into the 64-bit range.
See also
anj_time_duration_new
anj_time_real_new
anj_time_monotonic_new
anj_time_scalar_from_duration
ANJ_TIME_DURATION_AS_STRING

Macro Definition Documentation

◆ ANJ_TIME_DURATION_AS_STRING

#define ANJ_TIME_DURATION_AS_STRING (   duration,
  unit 
)
Value:
duration, \
unit, \
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.
#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

Formats a duration as a string in the given unit.

The macro allocates a temporary stack buffer and returns a pointer to it, making it convenient for logging:

anj_log(my_module, L_DEBUG, "Timeout=%s",
#define anj_log(Module, LogLevel,...)
Definition log.h:120
@ ANJ_TIME_UNIT_MS
Milliseconds (1000 microseconds).
Definition time.h:77
#define ANJ_TIME_DURATION_AS_STRING(duration, unit)
Formats a duration as a string in the given unit.
Definition time.h:410
Parameters
durationDuration to format.
unitUnit to print the value in.
Returns
const char * to a NUL-terminated string valid until the end of the full expression (implementation uses a compound literal).

◆ ANJ_TIME_DURATION_AS_STRING_MAX_LEN

#define ANJ_TIME_DURATION_AS_STRING_MAX_LEN   (sizeof("-9223372036854775808"))

Maximum length for buffers created by ANJ_TIME_DURATION_AS_STRING and related macros.

Includes one extra byte for a null terminator.

◆ ANJ_TIME_MONOTONIC_AS_STRING

#define ANJ_TIME_MONOTONIC_AS_STRING (   time,
  unit 
)
Value:
time.since_monotonic_epoch, \
unit, \

Formats a monotonic timestamp as a duration string in the given unit.

Useful for logs that want to show “time since boot” in milliseconds, etc.

Parameters
timeMonotonic timestamp.
unitUnit to print the value in.
Returns
Pointer to a temporary NUL-terminated string; see ANJ_TIME_DURATION_AS_STRING for lifetime details.

◆ ANJ_TIME_REAL_AS_STRING

#define ANJ_TIME_REAL_AS_STRING (   time,
  unit 
)
Value:
time.since_real_epoch, \
unit, \

Formats a real timestamp as a duration string in the given unit.

This prints the numeric offset from the Unix epoch (e.g., in seconds or milliseconds). For human-readable calendars, convert externally.

Parameters
timeReal timestamp.
unitUnit to print the value in.
Returns
Pointer to a temporary NUL-terminated string; see ANJ_TIME_DURATION_AS_STRING for lifetime details.

◆ ANJ_TIME_US_MAX

#define ANJ_TIME_US_MAX   INT64_MAX

Maximum value for a duration in microseconds.

Used as a sentinel to represent an invalid duration.

Enumeration Type Documentation

◆ anj_time_unit_t

Time unit of a scalar value.

Used by conversion helpers to interpret or present time quantities.

Enumerator
ANJ_TIME_UNIT_DAY 

Days (24 hours).

ANJ_TIME_UNIT_HOUR 

Hours (60 minutes).

ANJ_TIME_UNIT_MIN 

Minutes (60 seconds).

ANJ_TIME_UNIT_S 

Seconds (1000 milliseconds).

ANJ_TIME_UNIT_MS 

Milliseconds (1000 microseconds).

ANJ_TIME_UNIT_US 

Microseconds (1/1000 milliseconds).

Function Documentation

◆ _anj_time_duration_as_string_impl()

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.

Returns either:

  • a pointer to buffer with the formatted integer scalar in the requested unit,
  • the literal string "<invalid>" if duration equals ANJ_TIME_DURATION_INVALID, or
  • the literal string "<error>" on conversion failure.
Parameters
durationDuration to print.
unitUnit to print in.
bufferPointer to a character array of size ANJ_TIME_DURATION_AS_STRING_MAX_LEN.
Returns
Pointer to a C string as described above.

◆ anj_time_duration_add()

static anj_time_duration_t anj_time_duration_add ( const anj_time_duration_t  lhs,
const anj_time_duration_t  rhs 
)
inlinestatic

Adds two durations.

Parameters
lhsLeft-hand operand.
rhsRight-hand operand.
Returns
lhs + rhs, or ANJ_TIME_DURATION_INVALID if any operand is invalid.
Warning
No overflow checking is performed.

◆ anj_time_duration_div()

static anj_time_duration_t anj_time_duration_div ( const anj_time_duration_t  duration,
const int32_t  divisor 
)
inlinestatic

Divides a duration by an integer divisor.

Parameters
durationDuration to divide.
divisorInteger divisor (must not be 0).
Returns
Quotient duration, or ANJ_TIME_DURATION_INVALID if inputs are invalid or divisor is 0.
Warning
Division by zero is undefined. No overflow checking is performed.

◆ anj_time_duration_eq()

static bool anj_time_duration_eq ( const anj_time_duration_t  lhs,
const anj_time_duration_t  rhs 
)
inlinestatic

Equality comparison for durations.

◆ anj_time_duration_fmul()

static anj_time_duration_t anj_time_duration_fmul ( const anj_time_duration_t  duration,
const double  factor 
)
inlinestatic

Multiplies a duration by a floating-point factor.

The intermediate result is computed in double and then truncated when converted back to microseconds.

Parameters
durationDuration to scale.
factorFloating-point factor.
Returns
Scaled duration, or ANJ_TIME_DURATION_INVALID if inputs are invalid or factor is NaN/Inf.
Warning
Precision may be lost; no overflow checking is performed.

◆ anj_time_duration_fnew()

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.

The value is converted to microseconds and truncated toward zero.

Parameters
scalarFloating-point value to convert.
unitUnit of scalar.
Returns
Duration expressed in microseconds.
Warning
No overflow checking is performed. Precision may be lost due to conversion to integer microseconds.

◆ anj_time_duration_geq()

static bool anj_time_duration_geq ( const anj_time_duration_t  lhs,
const anj_time_duration_t  rhs 
)
inlinestatic

Greater-or-equal comparison for durations.

◆ anj_time_duration_gt()

static bool anj_time_duration_gt ( const anj_time_duration_t  lhs,
const anj_time_duration_t  rhs 
)
inlinestatic

Greater-than comparison for durations.

◆ anj_time_duration_is_valid()

static bool anj_time_duration_is_valid ( anj_time_duration_t  duration)
inlinestatic

Checks whether a duration value is valid.

Parameters
durationDuration to check.
Returns
true if duration is neither the invalid sentinel nor otherwise invalid; false otherwise.

◆ anj_time_duration_leq()

static bool anj_time_duration_leq ( const anj_time_duration_t  lhs,
const anj_time_duration_t  rhs 
)
inlinestatic

Less-or-equal comparison for durations.

◆ anj_time_duration_lt()

static bool anj_time_duration_lt ( const anj_time_duration_t  lhs,
const anj_time_duration_t  rhs 
)
inlinestatic

Less-than comparison for durations.

◆ anj_time_duration_mul()

static anj_time_duration_t anj_time_duration_mul ( const anj_time_duration_t  duration,
const int32_t  factor 
)
inlinestatic

Multiplies a duration by an integer factor.

Parameters
durationDuration to scale.
factorInteger factor.
Returns
Scaled duration, or ANJ_TIME_DURATION_INVALID if duration is invalid or factor is not supported.
Warning
No overflow checking is performed.

◆ anj_time_duration_new()

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.

Parameters
scalarInteger value to convert.
unitUnit of scalar.
Returns
Duration expressed in microseconds.
Warning
No overflow checking is performed.

◆ anj_time_duration_sub()

static anj_time_duration_t anj_time_duration_sub ( const anj_time_duration_t  lhs,
const anj_time_duration_t  rhs 
)
inlinestatic

Subtracts two durations.

Parameters
lhsLeft-hand operand.
rhsRight-hand operand.
Returns
lhs - rhs, or ANJ_TIME_DURATION_INVALID if any operand is invalid.
Warning
No overflow checking is performed.

◆ anj_time_duration_to_fscalar()

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.

Parameters
durationDuration to convert.
unitTarget unit.
Returns
Floating-point scalar value in unit.

◆ anj_time_duration_to_scalar()

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.

The value is truncated toward zero.

Parameters
durationDuration to convert.
unitTarget unit.
Returns
Integer scalar value in unit.

◆ anj_time_monotonic_add()

static anj_time_monotonic_t anj_time_monotonic_add ( const anj_time_monotonic_t  start,
const anj_time_duration_t  duration 
)
inlinestatic

Adds a relative duration to a monotonic timestamp.

Parameters
startBase monotonic time.
durationDuration to add.
Returns
start + duration.

◆ anj_time_monotonic_diff()

static anj_time_duration_t anj_time_monotonic_diff ( const anj_time_monotonic_t  end,
const anj_time_monotonic_t  start 
)
inlinestatic

Computes the difference between two monotonic timestamps.

Parameters
endLater timestamp.
startEarlier timestamp.
Returns
end - start as a duration (may be negative if end < start).

◆ anj_time_monotonic_eq()

static bool anj_time_monotonic_eq ( const anj_time_monotonic_t  lhs,
const anj_time_monotonic_t  rhs 
)
inlinestatic

Equality comparison for monotonic timestamps.

◆ anj_time_monotonic_fnew()

static anj_time_monotonic_t anj_time_monotonic_fnew ( const double  scalar,
const anj_time_unit_t  unit 
)
inlinestatic

Creates a monotonic timestamp from a floating-point scalar and unit.

Parameters
scalarFloating-point value.
unitUnit of scalar.
Returns
Monotonic timestamp.

◆ anj_time_monotonic_from_duration()

static anj_time_monotonic_t anj_time_monotonic_from_duration ( const anj_time_duration_t  duration)
inlinestatic

Constructs a monotonic timestamp from a duration since the monotonic epoch.

Parameters
durationDuration since the monotonic epoch.
Returns
Monotonic timestamp equal to duration after the epoch.

◆ anj_time_monotonic_geq()

static bool anj_time_monotonic_geq ( const anj_time_monotonic_t  lhs,
const anj_time_monotonic_t  rhs 
)
inlinestatic

Greater-or-equal comparison for monotonic timestamps.

◆ anj_time_monotonic_gt()

static bool anj_time_monotonic_gt ( const anj_time_monotonic_t  lhs,
const anj_time_monotonic_t  rhs 
)
inlinestatic

Greater-than comparison for monotonic timestamps.

◆ anj_time_monotonic_is_valid()

static bool anj_time_monotonic_is_valid ( const anj_time_monotonic_t  time)
inlinestatic

Checks whether a monotonic timestamp is valid.

Parameters
timeTimestamp to check.
Returns
true if valid; false otherwise.

◆ anj_time_monotonic_leq()

static bool anj_time_monotonic_leq ( const anj_time_monotonic_t  lhs,
const anj_time_monotonic_t  rhs 
)
inlinestatic

Less-or-equal comparison for monotonic timestamps.

◆ anj_time_monotonic_lt()

static bool anj_time_monotonic_lt ( const anj_time_monotonic_t  lhs,
const anj_time_monotonic_t  rhs 
)
inlinestatic

Less-than comparison for monotonic timestamps.

◆ anj_time_monotonic_new()

static anj_time_monotonic_t anj_time_monotonic_new ( const int64_t  scalar,
const anj_time_unit_t  unit 
)
inlinestatic

Creates a monotonic timestamp from an integer scalar and unit.

Parameters
scalarInteger value.
unitUnit of scalar.
Returns
Monotonic timestamp.

◆ anj_time_monotonic_sub()

static anj_time_monotonic_t anj_time_monotonic_sub ( const anj_time_monotonic_t  start,
const anj_time_duration_t  duration 
)
inlinestatic

Subtracts a relative duration from a monotonic timestamp.

Parameters
startBase monotonic time.
durationDuration to subtract.
Returns
start - duration.

◆ anj_time_monotonic_to_duration()

static anj_time_duration_t anj_time_monotonic_to_duration ( const anj_time_monotonic_t  time)
inlinestatic

Converts a monotonic timestamp to a duration since the monotonic epoch.

Parameters
timeMonotonic timestamp to convert.
Returns
Duration since the monotonic epoch.

◆ anj_time_monotonic_to_fscalar()

static double anj_time_monotonic_to_fscalar ( const anj_time_monotonic_t  time,
const anj_time_unit_t  unit 
)
inlinestatic

Converts a monotonic timestamp to a floating-point scalar.

Parameters
timeTimestamp to convert.
unitTarget unit.
Returns
Floating-point scalar.

◆ anj_time_monotonic_to_scalar()

static int64_t anj_time_monotonic_to_scalar ( const anj_time_monotonic_t  time,
const anj_time_unit_t  unit 
)
inlinestatic

Converts a monotonic timestamp to an integer scalar in the given unit.

Parameters
timeTimestamp to convert.
unitTarget unit.
Returns
Integer scalar.

◆ anj_time_real_add()

static anj_time_real_t anj_time_real_add ( const anj_time_real_t  start,
const anj_time_duration_t  duration 
)
inlinestatic

Adds a relative duration to a real timestamp.

Parameters
startBase real time.
durationDuration to add.
Returns
start + duration.

◆ anj_time_real_diff()

static anj_time_duration_t anj_time_real_diff ( const anj_time_real_t  end,
const anj_time_real_t  start 
)
inlinestatic

Computes the difference between two real timestamps.

Parameters
endLater timestamp.
startEarlier timestamp.
Returns
end - start as a duration (may be negative).

◆ anj_time_real_eq()

static bool anj_time_real_eq ( const anj_time_real_t  lhs,
const anj_time_real_t  rhs 
)
inlinestatic

Equality comparison for real timestamps.

◆ anj_time_real_fnew()

static anj_time_real_t anj_time_real_fnew ( const double  scalar,
const anj_time_unit_t  unit 
)
inlinestatic

Creates a real timestamp from a floating-point scalar and unit.

Parameters
scalarFloating-point value.
unitUnit of scalar.
Returns
Real timestamp.

◆ anj_time_real_from_duration()

static anj_time_real_t anj_time_real_from_duration ( const anj_time_duration_t  duration)
inlinestatic

Constructs a real (wall-clock) timestamp from a duration since Unix epoch.

Parameters
durationDuration since the Unix epoch.
Returns
Real timestamp equal to duration after the epoch.

◆ anj_time_real_geq()

static bool anj_time_real_geq ( const anj_time_real_t  lhs,
const anj_time_real_t  rhs 
)
inlinestatic

Greater-or-equal comparison for real timestamps.

◆ anj_time_real_gt()

static bool anj_time_real_gt ( const anj_time_real_t  lhs,
const anj_time_real_t  rhs 
)
inlinestatic

Greater-than comparison for real timestamps.

◆ anj_time_real_is_valid()

static bool anj_time_real_is_valid ( const anj_time_real_t  time)
inlinestatic

Checks whether a real timestamp is valid.

Parameters
timeTimestamp to check.
Returns
true if valid; false otherwise.

◆ anj_time_real_leq()

static bool anj_time_real_leq ( const anj_time_real_t  lhs,
const anj_time_real_t  rhs 
)
inlinestatic

Less-or-equal comparison for real timestamps.

◆ anj_time_real_lt()

static bool anj_time_real_lt ( const anj_time_real_t  lhs,
const anj_time_real_t  rhs 
)
inlinestatic

Less-than comparison for real timestamps.

◆ anj_time_real_new()

static anj_time_real_t anj_time_real_new ( const int64_t  scalar,
const anj_time_unit_t  unit 
)
inlinestatic

Creates a real timestamp from an integer scalar and unit.

Parameters
scalarInteger value.
unitUnit of scalar.
Returns
Real timestamp.

◆ anj_time_real_sub()

static anj_time_real_t anj_time_real_sub ( const anj_time_real_t  start,
const anj_time_duration_t  duration 
)
inlinestatic

Subtracts a relative duration from a real timestamp.

Parameters
startBase real time.
durationDuration to subtract.
Returns
start - duration.

◆ anj_time_real_to_duration()

static anj_time_duration_t anj_time_real_to_duration ( const anj_time_real_t  time)
inlinestatic

Converts a real timestamp to a duration since the Unix epoch.

Parameters
timeReal timestamp to convert.
Returns
Duration since the Unix epoch.

◆ anj_time_real_to_fscalar()

static double anj_time_real_to_fscalar ( const anj_time_real_t  time,
const anj_time_unit_t  unit 
)
inlinestatic

Converts a real timestamp to a floating-point scalar.

Parameters
timeReal timestamp to convert.
unitTarget unit.
Returns
Floating-point scalar.

◆ anj_time_real_to_scalar()

static int64_t anj_time_real_to_scalar ( const anj_time_real_t  time,
const anj_time_unit_t  unit 
)
inlinestatic

Converts a real timestamp to an integer scalar in the given unit.

Parameters
timeReal timestamp to convert.
unitTarget unit.
Returns
Integer scalar.

Variable Documentation

◆ ANJ_TIME_DURATION_INVALID

const anj_time_duration_t ANJ_TIME_DURATION_INVALID
extern

Sentinel duration representing “infinity”.

◆ ANJ_TIME_DURATION_ZERO

const anj_time_duration_t ANJ_TIME_DURATION_ZERO
extern

Zero duration (0 microseconds).

◆ ANJ_TIME_MONOTONIC_INVALID

const anj_time_monotonic_t ANJ_TIME_MONOTONIC_INVALID
extern

Sentinel monotonic time representing “infinity”.

◆ ANJ_TIME_MONOTONIC_ZERO

const anj_time_monotonic_t ANJ_TIME_MONOTONIC_ZERO
extern

Monotonic time set to 0 (monotonic epoch).

◆ ANJ_TIME_REAL_INVALID

const anj_time_real_t ANJ_TIME_REAL_INVALID
extern

Sentinel real time representing “infinity”.

◆ ANJ_TIME_REAL_ZERO

const anj_time_real_t ANJ_TIME_REAL_ZERO
extern

Real time set to 0 (Unix epoch).