The FreeRADIUS server  $Id: 15bac2a4c627c01d1aa2047687b3418955ac7f00 $
Data Structures | Macros | Typedefs | Enumerations | Functions | Variables
time.h File Reference

Simple time functions. More...

#include <stdint.h>
#include <inttypes.h>
#include <stdatomic.h>
#include <stdio.h>
#include <sys/time.h>
#include <freeradius-devel/missing.h>
#include <freeradius-devel/util/debug.h>
#include <freeradius-devel/util/sbuff.h>
#include <freeradius-devel/util/math.h>
+ Include dependency graph for time.h:
+ This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  fr_time_delta_s
 A time delta, a difference in time measured in nanoseconds. More...
 
struct  fr_time_elapsed_t
 
struct  fr_time_s
 "server local" time. More...
 
struct  fr_unix_time_s
 "Unix" time. More...
 

Macros

#define CLOCK_MONOTONIC_RAW   CLOCK_MONOTONIC
 
#define CSEC   (100)
 
#define fr_time_delta_max()   (fr_time_delta_t){ .value = INT64_MAX }
 
#define fr_time_delta_min()   (fr_time_delta_t){ .value = INT64_MIN }
 
#define fr_time_delta_overflow_add(_a, _b)   (fr_time_overflow_ispos(_a, true, _b) ? fr_time_delta_max() : fr_time_delta_min())
 
#define fr_time_delta_overflow_sub(_a, _b)   (fr_time_overflow_ispos(_a, false, _b) ? fr_time_delta_max() : fr_time_delta_min())
 
#define fr_time_delta_wrap(_time)   (fr_time_delta_t){ .value = (_time) }
 
#define FR_TIME_DUR_MONTH   (FR_TIME_DUR_YEAR/12)
 
#define FR_TIME_DUR_YEAR   ((int64_t)NSEC * 31556952)
 
#define fr_time_max()   (fr_time_t){ .value = INT64_MAX }
 
#define fr_time_min()   (fr_time_t){ .value = INT64_MIN }
 
#define fr_time_overflow_add(_a, _b)   (fr_time_overflow_ispos(_a, true, _b) ? fr_time_max() : fr_time_min())
 
#define fr_time_overflow_ispos(_a, _op, _b)
 Determine, if an overflow has occurred, which direction it occurred in. More...
 
#define fr_time_overflow_sub(_a, _b)   (fr_time_overflow_ispos(_a, false, _b) ? fr_time_max() : fr_time_min())
 
#define fr_time_wrap(_time)   (fr_time_t){ .value = (_time) }
 
#define fr_unix_time_max()   (fr_unix_time_t){ .value = UINT64_MAX }
 
#define fr_unix_time_min()   (fr_unix_time_t){ .value = 0 }
 
#define fr_unix_time_overflow_add(_a, _b)   (fr_time_overflow_ispos(_a, true, _b) ? fr_unix_time_max() : fr_unix_time_min())
 
#define fr_unix_time_overflow_sub(_a, _b)   (fr_time_overflow_ispos(_a, false, _b) ? fr_unix_time_max() : fr_unix_time_min())
 
#define fr_unix_time_wrap(_time)   (fr_unix_time_t){ .value = (_time) }
 
#define MSEC   (1000)
 
#define NSEC   (1000000000)
 
#define USEC   (1000000)
 

Typedefs

typedef struct fr_time_delta_s fr_time_delta_t
 A time delta, a difference in time measured in nanoseconds. More...
 
typedef struct fr_time_s fr_time_t
 "server local" time. More...
 
typedef struct fr_unix_time_s fr_unix_time_t
 "Unix" time. More...
 

Enumerations

enum  fr_time_res_t {
  FR_TIME_RES_INVALID = -1 ,
  FR_TIME_RES_SEC = 0 ,
  FR_TIME_RES_MIN ,
  FR_TIME_RES_HOUR ,
  FR_TIME_RES_DAY ,
  FR_TIME_RES_WEEK ,
  FR_TIME_RES_MONTH ,
  FR_TIME_RES_YEAR ,
  FR_TIME_RES_CSEC ,
  FR_TIME_RES_MSEC ,
  FR_TIME_RES_USEC ,
  FR_TIME_RES_NSEC
}
 The base resolution for print parse operations. More...
 

Functions

static fr_time_t fr_time (void)
 Return a relative time since the server fr_time_epoch. More...
 
static int8_t fr_time_cmp (fr_time_t a, fr_time_t b)
 Compare two fr_time_t values. More...
 
static int8_t fr_time_delta_cmp (fr_time_delta_t a, fr_time_delta_t b)
 Compare two fr_time_delta_t values. More...
 
fr_slen_t fr_time_delta_from_str (fr_time_delta_t *out, char const *in, size_t inlen, fr_time_res_t hint)
 Create fr_time_delta_t from a string. More...
 
fr_slen_t fr_time_delta_from_substr (fr_time_delta_t *out, fr_sbuff_t *in, fr_time_res_t hint, bool no_trailing, fr_sbuff_term_t const *tt))
 Create fr_time_delta_t from a string. More...
 
int fr_time_delta_from_time_zone (char const *tz, fr_time_delta_t *delta)
 Return time delta from the time zone. More...
 
fr_slen_t fr_time_delta_to_str (fr_sbuff_t *out, fr_time_delta_t delta, fr_time_res_t res, bool is_unsigned)
 Print fr_time_delta_t to a string with an appropriate suffix. More...
 
static int64_t fr_time_delta_unwrap (fr_time_delta_t time)
 
void fr_time_elapsed_fprint (FILE *fp, fr_time_elapsed_t const *elapsed, char const *prefix, int tabs))
 
void fr_time_elapsed_update (fr_time_elapsed_t *elapsed, fr_time_t start, fr_time_t end)
 
fr_time_delta_t fr_time_gmtoff (void)
 Get the offset to gmt. More...
 
bool fr_time_is_dst (void)
 Whether or not we're daylight savings. More...
 
static bool fr_time_op_ispos (bool a, bool op, bool b)
 
int64_t fr_time_scale (int64_t t, fr_time_res_t hint)
 Scale an input time to NSEC, clamping it at max / min. More...
 
int fr_time_start (void)
 Initialize the local time. More...
 
size_t fr_time_strftime_local (fr_sbuff_t *out, fr_time_t time, char const *fmt))
 Copy a time string (local timezone) to an sbuff. More...
 
size_t fr_time_strftime_utc (fr_sbuff_t *out, fr_time_t time, char const *fmt))
 Copy a time string (UTC) to an sbuff. More...
 
int fr_time_sync (void)
 Get a new fr_time_monotonic_to_realtime value. More...
 
static int64_t fr_time_unwrap (fr_time_t time)
 
static int8_t fr_unix_time_cmp (fr_unix_time_t a, fr_unix_time_t b)
 Compare two fr_unix_time_t values. More...
 
int fr_unix_time_from_str (fr_unix_time_t *date, char const *date_str, fr_time_res_t hint)
 Convert string in various formats to a fr_unix_time_t. More...
 
fr_unix_time_t fr_unix_time_from_tm (struct tm *tm)
 
fr_slen_t fr_unix_time_to_str (fr_sbuff_t *out, fr_unix_time_t time, fr_time_res_t res, bool utc)
 Convert unix time to string. More...
 
static uint64_t fr_unix_time_unwrap (fr_unix_time_t time)
 

Variables

int64_t fr_time_epoch
 monotonic clock at boot, i.e. our epoch More...
 
_Atomic int64_t fr_time_monotonic_to_realtime
 difference between the two clocks More...
 
int64_t const fr_time_multiplier_by_res []
 
fr_table_num_ordered_t const fr_time_precision_table []
 
size_t fr_time_precision_table_len
 

fr_time_t arithmetic and comparison macros

We wrap the 64bit signed time value in a struct to prevent misuse.

The macros below allow basic arithmetic and comparisons to be performed.

#define fr_time_add(_a, _b)
 Add a time/time delta together. More...
 
static fr_time_t fr_time_add_delta_time (fr_time_delta_t a, fr_time_t b)
 
static fr_time_t fr_time_add_time_delta (fr_time_t a, fr_time_delta_t b)
 
#define fr_time_eq(_a, _b)   (fr_time_unwrap(_a) == fr_time_unwrap(_b))
 
#define fr_time_gt(_a, _b)   (fr_time_unwrap(_a) > fr_time_unwrap(_b))
 
#define fr_time_gteq(_a, _b)   (fr_time_unwrap(_a) >= fr_time_unwrap(_b))
 
#define fr_time_isneg(_a)   (fr_time_unwrap(_a) < 0)
 
#define fr_time_ispos(_a)   (fr_time_unwrap(_a) > 0)
 
#define fr_time_lt(_a, _b)   (fr_time_unwrap(_a) < fr_time_unwrap(_b))
 
#define fr_time_lteq(_a, _b)   (fr_time_unwrap(_a) <= fr_time_unwrap(_b))
 
#define fr_time_neq(_a, _b)   (fr_time_unwrap(_a) != fr_time_unwrap(_b))
 
#define fr_time_sub(_a, _b)
 Subtract one time from another. More...
 
static fr_time_t fr_time_sub_time_delta (fr_time_t a, fr_time_delta_t b)
 
static fr_time_delta_t fr_time_sub_time_time (fr_time_t a, fr_time_t b)
 

fr_time_delta_t arithmetic and comparison macros

We wrap the 64bit signed time delta value in a struct to prevent misuse.

The macros below allow basic arithmetic and comparisons to be performed.

static fr_time_delta_t fr_time_delta_add (fr_time_delta_t a, fr_time_delta_t b)
 
#define fr_time_delta_cond(_a, _op, _b)   (fr_time_delta_unwrap(_a) _op fr_time_delta_unwrap(_b))
 
static fr_time_delta_t fr_time_delta_div (fr_time_delta_t a, fr_time_delta_t b)
 
#define fr_time_delta_eq(_a, _b)   (fr_time_delta_unwrap(_a) == fr_time_delta_unwrap(_b))
 
#define fr_time_delta_gt(_a, _b)   (fr_time_delta_unwrap(_a) > fr_time_delta_unwrap(_b))
 
#define fr_time_delta_gteq(_a, _b)   (fr_time_delta_unwrap(_a) >= fr_time_delta_unwrap(_b))
 
#define fr_time_delta_isneg(_a)   (fr_time_delta_unwrap(_a) < 0)
 
#define fr_time_delta_ispos(_a)   (fr_time_delta_unwrap(_a) > 0)
 
#define fr_time_delta_lt(_a, _b)   (fr_time_delta_unwrap(_a) < fr_time_delta_unwrap(_b))
 
#define fr_time_delta_lteq(_a, _b)   (fr_time_delta_unwrap(_a) <= fr_time_delta_unwrap(_b))
 
static fr_time_delta_t fr_time_delta_mul (fr_time_delta_t a, int64_t b)
 
#define fr_time_delta_neq(_a, _b)   (fr_time_delta_unwrap(_a) != fr_time_delta_unwrap(_b))
 
static fr_time_delta_t fr_time_delta_sub (fr_time_delta_t a, fr_time_delta_t b)
 

fr_unix_time_t arithmetic and comparison macros

We wrap the 64bit signed time value in a struct to prevent misuse.

The macros below allow basic arithmetic and comparisons to be performed.

#define fr_unix_time_add(_a, _b)
 Add a time/time delta together. More...
 
static fr_unix_time_t fr_unix_time_add_delta_time (fr_time_delta_t a, fr_unix_time_t b)
 
static fr_unix_time_t fr_unix_time_add_time_delta (fr_unix_time_t a, fr_time_delta_t b)
 
#define fr_unix_time_eq(_a, _b)   (fr_unix_time_unwrap(_a) == fr_unix_time_unwrap(_b))
 
#define fr_unix_time_gt(_a, _b)   (fr_unix_time_unwrap(_a) > fr_unix_time_unwrap(_b))
 
#define fr_unix_time_gteq(_a, _b)   (fr_unix_time_unwrap(_a) >= fr_unix_time_unwrap(_b))
 
#define fr_unix_time_ispos(_a)   (fr_unix_time_unwrap(_a) > 0)
 
#define fr_unix_time_lt(_a, _b)   (fr_unix_time_unwrap(_a) < fr_unix_time_unwrap(_b))
 
#define fr_unix_time_lteq(_a, _b)   (fr_unix_time_unwrap(_a) <= fr_unix_time_unwrap(_b))
 
#define fr_unix_time_neq(_a, _b)   (fr_unix_time_unwrap(_a) != fr_unix_time_unwrap(_b))
 
#define fr_unix_time_sub(_a, _b)
 Subtract one time from another. More...
 
static fr_unix_time_t fr_unix_time_sub_time_delta (fr_unix_time_t a, fr_time_delta_t b)
 
static fr_time_delta_t fr_unix_time_sub_time_time (fr_unix_time_t a, fr_unix_time_t b)
 

fr_time_delta_t scale conversion macros/functions

static fr_time_delta_t fr_time_delta_from_csec (int64_t csec)
 
static fr_time_delta_t fr_time_delta_from_integer (bool *overflow, int64_t integer, fr_time_res_t res)
 
static fr_time_delta_t fr_time_delta_from_msec (int64_t msec)
 
static fr_time_delta_t fr_time_delta_from_nsec (int64_t nsec)
 
static fr_time_delta_t fr_time_delta_from_sec (int64_t sec)
 
static fr_time_delta_t fr_time_delta_from_timespec (struct timespec const *ts)
 
static fr_time_delta_t fr_time_delta_from_timeval (struct timeval const *tv)
 
static fr_time_delta_t fr_time_delta_from_usec (int64_t usec)
 
static int64_t fr_time_delta_to_csec (fr_time_delta_t delta)
 
static int64_t fr_time_delta_to_integer (fr_time_delta_t delta, fr_time_res_t res)
 
static int64_t fr_time_delta_to_msec (fr_time_delta_t delta)
 
static int64_t fr_time_delta_to_sec (fr_time_delta_t delta)
 
#define fr_time_delta_to_timespec(_delta)
 Convert a delta to a timespec. More...
 
#define fr_time_delta_to_timeval(_delta)
 Convert a delta to a timeval. More...
 
static int64_t fr_time_delta_to_usec (fr_time_delta_t delta)
 
static fr_time_t fr_time_from_csec (int64_t when)
 Convert csec (wallclock time) to a fr_time_t (internal time) More...
 
static fr_time_t fr_time_from_integer (bool *overflow, int64_t when, fr_time_res_t res)
 Convert wallclock time to a fr_time_t (internal time) More...
 
static fr_time_t fr_time_from_msec (int64_t when)
 Convert msec (wallclock time) to a fr_time_t (internal time) More...
 
static fr_time_t fr_time_from_nsec (int64_t when)
 Convert a nsec (wallclock time) to a fr_time_t (internal time) More...
 
static fr_time_t fr_time_from_sec (time_t when)
 Convert a time_t (wallclock time) to a fr_time_t (internal time) More...
 
static fr_time_t fr_time_from_timespec (struct timespec const *when_ts)
 Convert a timespec (wallclock time) to a fr_time_t (internal time) More...
 
static fr_time_t fr_time_from_timeval (struct timeval const *when_tv)
 Convert a timeval (wallclock time) to a fr_time_t (internal time) More...
 
static fr_time_t fr_time_from_usec (int64_t when)
 Convert usec (wallclock time) to a fr_time_t (internal time) More...
 
static int64_t fr_time_offset_to_realtime (void)
 Return the current value of fr_time_monotonic_to_realtime. More...
 
static int64_t fr_time_to_csec (fr_time_t when)
 Convert an fr_time_t (internal time) to number of csec since the unix epoch (wallclock time) More...
 
static int64_t fr_time_to_msec (fr_time_t when)
 Convert an fr_time_t (internal time) to number of msec since the unix epoch (wallclock time) More...
 
static int64_t fr_time_to_sec (fr_time_t when)
 Convert an fr_time_t (internal time) to number of sec since the unix epoch (wallclock time) More...
 
#define fr_time_to_timespec(_when)   fr_time_delta_to_timespec(fr_time_delta_wrap(fr_time_offset_to_realtime() + fr_time_unwrap(_when)))
 Convert server epoch time to unix epoch time. More...
 
#define fr_time_to_timeval(_when)   fr_time_delta_to_timeval(fr_time_delta_wrap(fr_time_offset_to_realtime() + fr_time_unwrap(_when)))
 Convert server epoch time to unix epoch time. More...
 
static fr_unix_time_t fr_time_to_unix_time (fr_time_t when)
 Convert an fr_time_t (internal time) to our version of unix time (wallclock time) More...
 
static int64_t fr_time_to_usec (fr_time_t when)
 Convert an fr_time_t (internal time) to number of usec since the unix epoch (wallclock time) More...
 

fr_unix_time_t scale conversion macros/functions

static fr_unix_time_t fr_unix_time_from_csec (int64_t csec)
 
static fr_unix_time_t fr_unix_time_from_integer (bool *overflow, int64_t integer, fr_time_res_t res)
 
static fr_unix_time_t fr_unix_time_from_msec (int64_t msec)
 
static fr_unix_time_t fr_unix_time_from_nsec (int64_t nsec)
 
static fr_unix_time_t fr_unix_time_from_sec (int64_t sec)
 
static fr_unix_time_t fr_unix_time_from_time (time_t time)
 Convert a time_t into out internal fr_unix_time_t. More...
 
static fr_unix_time_t fr_unix_time_from_timespec (struct timespec const *ts)
 
static fr_unix_time_t fr_unix_time_from_timeval (struct timeval const *tv)
 
static fr_unix_time_t fr_unix_time_from_usec (int64_t usec)
 
static int64_t fr_unix_time_to_csec (fr_unix_time_t delta)
 
static int64_t fr_unix_time_to_day (fr_unix_time_t delta)
 
static int64_t fr_unix_time_to_hour (fr_unix_time_t delta)
 
static int64_t fr_unix_time_to_integer (fr_unix_time_t delta, fr_time_res_t res)
 
static int64_t fr_unix_time_to_min (fr_unix_time_t delta)
 
static int64_t fr_unix_time_to_msec (fr_unix_time_t delta)
 
static int64_t fr_unix_time_to_sec (fr_unix_time_t delta)
 
static int64_t fr_unix_time_to_usec (fr_unix_time_t delta)
 

Detailed Description

Simple time functions.

Id
8b88a88bde62d1f04e9478da459d19c419a206b7

Definition in file time.h.


Data Structure Documentation

◆ fr_time_delta_s

struct fr_time_delta_s

A time delta, a difference in time measured in nanoseconds.

This is easier to distinguish where server epoch time is being used, and where relative time is being used.

Definition at line 80 of file time.h.

Data Fields
int64_t value

◆ fr_time_elapsed_t

struct fr_time_elapsed_t

Definition at line 375 of file time.h.

Data Fields
uint64_t array[8] 100ns to 100s

◆ fr_time_s

struct fr_time_s

"server local" time.

This is the time in nanoseconds since the application started.

This time is our private view of time. It should only be used for internal timers, events, etc. It can skew randomly as NTP plays with the local clock.

Definition at line 69 of file time.h.

Data Fields
int64_t value Signed because we need times before the server started for things like certificate validity checks and cache entries.

◆ fr_unix_time_s

struct fr_unix_time_s

"Unix" time.

This is the time in nanoseconds since midnight January 1, 1970

Note that it is unsigned, as we don't use dates before 1970. Having it unsigned also allows the compiler to catch issues where people confuse the two types of time.

The unix times are public times. i.e. times that we get from the network, or send to the network. We have no idea if the other parties idea of time is correct (or if ours is wrong), so we don't mangle unix time based on clock skew.

Definition at line 95 of file time.h.

Data Fields
uint64_t value

Macro Definition Documentation

◆ CLOCK_MONOTONIC_RAW

#define CLOCK_MONOTONIC_RAW   CLOCK_MONOTONIC

Definition at line 950 of file time.h.

◆ CSEC

#define CSEC   (100)

Definition at line 382 of file time.h.

◆ fr_time_add

#define fr_time_add (   _a,
  _b 
)
Value:
_Generic(_a, \
fr_time_t : _Generic(_b, \
), \
fr_time_delta_t : _Generic(_b, \
) \
)(_a, _b)
static fr_time_delta_t fr_time_delta_add(fr_time_delta_t a, fr_time_delta_t b)
Definition: time.h:255
static fr_time_t fr_time_add_time_delta(fr_time_t a, fr_time_delta_t b)
Definition: time.h:173
static fr_time_t fr_time_add_delta_time(fr_time_delta_t a, fr_time_t b)
Definition: time.h:180
A time delta, a difference in time measured in nanoseconds.
Definition: time.h:80
"server local" time.
Definition: time.h:69

Add a time/time delta together.

Types may either be:

  • fr_time_add((fr_time_t), (fr_time_delta_t))
  • fr_time_add((fr_time_delta_t), (fr_time_delta_t))

Adding two time values together is most likely an error. Adding two time_delta values together can be done with fr_time_delta_add.

Definition at line 196 of file time.h.

◆ fr_time_delta_cond

#define fr_time_delta_cond (   _a,
  _op,
  _b 
)    (fr_time_delta_unwrap(_a) _op fr_time_delta_unwrap(_b))

Definition at line 282 of file time.h.

◆ fr_time_delta_eq

#define fr_time_delta_eq (   _a,
  _b 
)    (fr_time_delta_unwrap(_a) == fr_time_delta_unwrap(_b))

Definition at line 287 of file time.h.

◆ fr_time_delta_gt

#define fr_time_delta_gt (   _a,
  _b 
)    (fr_time_delta_unwrap(_a) > fr_time_delta_unwrap(_b))

Definition at line 283 of file time.h.

◆ fr_time_delta_gteq

#define fr_time_delta_gteq (   _a,
  _b 
)    (fr_time_delta_unwrap(_a) >= fr_time_delta_unwrap(_b))

Definition at line 284 of file time.h.

◆ fr_time_delta_isneg

#define fr_time_delta_isneg (   _a)    (fr_time_delta_unwrap(_a) < 0)

Definition at line 291 of file time.h.

◆ fr_time_delta_ispos

#define fr_time_delta_ispos (   _a)    (fr_time_delta_unwrap(_a) > 0)

Definition at line 290 of file time.h.

◆ fr_time_delta_lt

#define fr_time_delta_lt (   _a,
  _b 
)    (fr_time_delta_unwrap(_a) < fr_time_delta_unwrap(_b))

Definition at line 285 of file time.h.

◆ fr_time_delta_lteq

#define fr_time_delta_lteq (   _a,
  _b 
)    (fr_time_delta_unwrap(_a) <= fr_time_delta_unwrap(_b))

Definition at line 286 of file time.h.

◆ fr_time_delta_max

#define fr_time_delta_max ( )    (fr_time_delta_t){ .value = INT64_MAX }

Definition at line 150 of file time.h.

◆ fr_time_delta_min

#define fr_time_delta_min ( )    (fr_time_delta_t){ .value = INT64_MIN }

Definition at line 151 of file time.h.

◆ fr_time_delta_neq

#define fr_time_delta_neq (   _a,
  _b 
)    (fr_time_delta_unwrap(_a) != fr_time_delta_unwrap(_b))

Definition at line 288 of file time.h.

◆ fr_time_delta_overflow_add

#define fr_time_delta_overflow_add (   _a,
  _b 
)    (fr_time_overflow_ispos(_a, true, _b) ? fr_time_delta_max() : fr_time_delta_min())

Definition at line 155 of file time.h.

◆ fr_time_delta_overflow_sub

#define fr_time_delta_overflow_sub (   _a,
  _b 
)    (fr_time_overflow_ispos(_a, false, _b) ? fr_time_delta_max() : fr_time_delta_min())

Definition at line 156 of file time.h.

◆ fr_time_delta_to_timespec

#define fr_time_delta_to_timespec (   _delta)
Value:
(struct timespec){ \
.tv_sec = fr_time_delta_unwrap(_delta) / NSEC, \
.tv_nsec = (fr_time_delta_unwrap(_delta) % NSEC) \
}
static int64_t fr_time_delta_unwrap(fr_time_delta_t time)
Definition: time.h:154
#define NSEC
Definition: time.h:379

Convert a delta to a timespec.

Parameters
[in]_deltain nanoseconds.

Definition at line 666 of file time.h.

◆ fr_time_delta_to_timeval

#define fr_time_delta_to_timeval (   _delta)
Value:
(struct timeval){ \
.tv_sec = fr_time_delta_unwrap(_delta) / NSEC, \
.tv_usec = (fr_time_delta_unwrap(_delta) % NSEC) / (NSEC / USEC) \
}
#define USEC
Definition: time.h:380

Convert a delta to a timeval.

Parameters
[in]_deltain nanoseconds.

Definition at line 656 of file time.h.

◆ fr_time_delta_wrap

#define fr_time_delta_wrap (   _time)    (fr_time_delta_t){ .value = (_time) }

Definition at line 152 of file time.h.

◆ FR_TIME_DUR_MONTH

#define FR_TIME_DUR_MONTH   (FR_TIME_DUR_YEAR/12)

Definition at line 394 of file time.h.

◆ FR_TIME_DUR_YEAR

#define FR_TIME_DUR_YEAR   ((int64_t)NSEC * 31556952)

Definition at line 393 of file time.h.

◆ fr_time_eq

#define fr_time_eq (   _a,
  _b 
)    (fr_time_unwrap(_a) == fr_time_unwrap(_b))

Definition at line 241 of file time.h.

◆ fr_time_gt

#define fr_time_gt (   _a,
  _b 
)    (fr_time_unwrap(_a) > fr_time_unwrap(_b))

Definition at line 237 of file time.h.

◆ fr_time_gteq

#define fr_time_gteq (   _a,
  _b 
)    (fr_time_unwrap(_a) >= fr_time_unwrap(_b))

Definition at line 238 of file time.h.

◆ fr_time_isneg

#define fr_time_isneg (   _a)    (fr_time_unwrap(_a) < 0)

Definition at line 245 of file time.h.

◆ fr_time_ispos

#define fr_time_ispos (   _a)    (fr_time_unwrap(_a) > 0)

Definition at line 244 of file time.h.

◆ fr_time_lt

#define fr_time_lt (   _a,
  _b 
)    (fr_time_unwrap(_a) < fr_time_unwrap(_b))

Definition at line 239 of file time.h.

◆ fr_time_lteq

#define fr_time_lteq (   _a,
  _b 
)    (fr_time_unwrap(_a) <= fr_time_unwrap(_b))

Definition at line 240 of file time.h.

◆ fr_time_max

#define fr_time_max ( )    (fr_time_t){ .value = INT64_MAX }

Definition at line 143 of file time.h.

◆ fr_time_min

#define fr_time_min ( )    (fr_time_t){ .value = INT64_MIN }

Definition at line 144 of file time.h.

◆ fr_time_neq

#define fr_time_neq (   _a,
  _b 
)    (fr_time_unwrap(_a) != fr_time_unwrap(_b))

Definition at line 242 of file time.h.

◆ fr_time_overflow_add

#define fr_time_overflow_add (   _a,
  _b 
)    (fr_time_overflow_ispos(_a, true, _b) ? fr_time_max() : fr_time_min())

Definition at line 147 of file time.h.

◆ fr_time_overflow_ispos

#define fr_time_overflow_ispos (   _a,
  _op,
  _b 
)
Value:
_Generic(&(_a), \
fr_time_t *: (fr_time_unwrap(*((fr_time_t *)&(_a))) >= 0), \
fr_unix_time_t *: true), \
_op, \
_Generic(&(_b), \
fr_time_t *: (fr_time_unwrap(*((fr_time_t *)&(_b))) >= 0), \
fr_unix_time_t *: true)\
)
static int64_t fr_time_unwrap(fr_time_t time)
Definition: time.h:146
static bool fr_time_op_ispos(bool a, bool op, bool b)
Definition: time.h:119
"Unix" time.
Definition: time.h:95

Determine, if an overflow has occurred, which direction it occurred in.

Parameters
[in]_aFirst operand.
[in]_opOperator, true if add or multiply, false if subtract.
[in]_bSecond operand.

Definition at line 130 of file time.h.

◆ fr_time_overflow_sub

#define fr_time_overflow_sub (   _a,
  _b 
)    (fr_time_overflow_ispos(_a, false, _b) ? fr_time_max() : fr_time_min())

Definition at line 148 of file time.h.

◆ fr_time_sub

#define fr_time_sub (   _a,
  _b 
)
Value:
_Generic(_a, \
fr_time_t : _Generic(_b, \
) \
)(_a, _b)
static fr_time_delta_t fr_time_sub_time_time(fr_time_t a, fr_time_t b)
Definition: time.h:207
static fr_time_t fr_time_sub_time_delta(fr_time_t a, fr_time_delta_t b)
Definition: time.h:213

Subtract one time from another.

Types may either be:

  • fr_time_sub((fr_time_t), (fr_time_t)) - Produces a fr_time_delta_t
  • fr_time_sub((fr_time_t), (fr_time_delta_t)) - Produces a fr_time_t

Subtracting time from a delta is most likely an error. Subtracting two time_delta values can be done with fr_time_delta_sub

Definition at line 229 of file time.h.

◆ fr_time_to_timespec

Convert server epoch time to unix epoch time.

Parameters
[in]_whenThe server epoch time to convert.

Definition at line 748 of file time.h.

◆ fr_time_to_timeval

Convert server epoch time to unix epoch time.

Parameters
[in]_whenThe server epoch time to convert.

Definition at line 742 of file time.h.

◆ fr_time_wrap

#define fr_time_wrap (   _time)    (fr_time_t){ .value = (_time) }

Definition at line 145 of file time.h.

◆ fr_unix_time_add

#define fr_unix_time_add (   _a,
  _b 
)
Value:
_Generic(_a, \
fr_unix_time_t : _Generic(_b, \
), \
fr_time_delta_t : _Generic(_b, \
) \
)(_a, _b)
static fr_unix_time_t fr_unix_time_add_delta_time(fr_time_delta_t a, fr_unix_time_t b)
Definition: time.h:308
static fr_unix_time_t fr_unix_time_add_time_delta(fr_unix_time_t a, fr_time_delta_t b)
Definition: time.h:302

Add a time/time delta together.

Types may either be:

  • fr_unix_time_add((fr_unix_time_t), (fr_time_delta_t))
  • fr_unix_time_add((fr_time_delta_t), (fr_time_delta_t))

Adding two time values together is most likely an error. Adding two time_delta values together can be done with fr_time_delta_add.

Definition at line 324 of file time.h.

◆ fr_unix_time_eq

#define fr_unix_time_eq (   _a,
  _b 
)    (fr_unix_time_unwrap(_a) == fr_unix_time_unwrap(_b))

Definition at line 369 of file time.h.

◆ fr_unix_time_gt

#define fr_unix_time_gt (   _a,
  _b 
)    (fr_unix_time_unwrap(_a) > fr_unix_time_unwrap(_b))

Definition at line 365 of file time.h.

◆ fr_unix_time_gteq

#define fr_unix_time_gteq (   _a,
  _b 
)    (fr_unix_time_unwrap(_a) >= fr_unix_time_unwrap(_b))

Definition at line 366 of file time.h.

◆ fr_unix_time_ispos

#define fr_unix_time_ispos (   _a)    (fr_unix_time_unwrap(_a) > 0)

Definition at line 372 of file time.h.

◆ fr_unix_time_lt

#define fr_unix_time_lt (   _a,
  _b 
)    (fr_unix_time_unwrap(_a) < fr_unix_time_unwrap(_b))

Definition at line 367 of file time.h.

◆ fr_unix_time_lteq

#define fr_unix_time_lteq (   _a,
  _b 
)    (fr_unix_time_unwrap(_a) <= fr_unix_time_unwrap(_b))

Definition at line 368 of file time.h.

◆ fr_unix_time_max

#define fr_unix_time_max ( )    (fr_unix_time_t){ .value = UINT64_MAX }

Definition at line 158 of file time.h.

◆ fr_unix_time_min

#define fr_unix_time_min ( )    (fr_unix_time_t){ .value = 0 }

Definition at line 159 of file time.h.

◆ fr_unix_time_neq

#define fr_unix_time_neq (   _a,
  _b 
)    (fr_unix_time_unwrap(_a) != fr_unix_time_unwrap(_b))

Definition at line 370 of file time.h.

◆ fr_unix_time_overflow_add

#define fr_unix_time_overflow_add (   _a,
  _b 
)    (fr_time_overflow_ispos(_a, true, _b) ? fr_unix_time_max() : fr_unix_time_min())

Definition at line 162 of file time.h.

◆ fr_unix_time_overflow_sub

#define fr_unix_time_overflow_sub (   _a,
  _b 
)    (fr_time_overflow_ispos(_a, false, _b) ? fr_unix_time_max() : fr_unix_time_min())

Definition at line 163 of file time.h.

◆ fr_unix_time_sub

#define fr_unix_time_sub (   _a,
  _b 
)
Value:
_Generic(_a, \
fr_unix_time_t : _Generic(_b, \
) \
)(_a, _b)
static fr_unix_time_t fr_unix_time_sub_time_delta(fr_unix_time_t a, fr_time_delta_t b)
Definition: time.h:341
static fr_time_delta_t fr_unix_time_sub_time_time(fr_unix_time_t a, fr_unix_time_t b)
Definition: time.h:335

Subtract one time from another.

Types may either be:

  • fr_unix_time_sub((fr_unix_time_t), (fr_unix_time_t)) - Produces a fr_time_delta_t
  • fr_unix_time_sub((fr_unix_time_t), (fr_time_delta_t)) - Produces a fr_unix_time_t

Subtracting time from a delta is most likely an error. Subtracting two time_delta values can be done with fr_time_delta_sub

Definition at line 357 of file time.h.

◆ fr_unix_time_wrap

#define fr_unix_time_wrap (   _time)    (fr_unix_time_t){ .value = (_time) }

Definition at line 160 of file time.h.

◆ MSEC

#define MSEC   (1000)

Definition at line 381 of file time.h.

◆ NSEC

#define NSEC   (1000000000)

Definition at line 379 of file time.h.

◆ USEC

#define USEC   (1000000)

Definition at line 380 of file time.h.

Typedef Documentation

◆ fr_time_delta_t

A time delta, a difference in time measured in nanoseconds.

This is easier to distinguish where server epoch time is being used, and where relative time is being used.

◆ fr_time_t

typedef struct fr_time_s fr_time_t

"server local" time.

This is the time in nanoseconds since the application started.

This time is our private view of time. It should only be used for internal timers, events, etc. It can skew randomly as NTP plays with the local clock.

◆ fr_unix_time_t

"Unix" time.

This is the time in nanoseconds since midnight January 1, 1970

Note that it is unsigned, as we don't use dates before 1970. Having it unsigned also allows the compiler to catch issues where people confuse the two types of time.

The unix times are public times. i.e. times that we get from the network, or send to the network. We have no idea if the other parties idea of time is correct (or if ours is wrong), so we don't mangle unix time based on clock skew.

Enumeration Type Documentation

◆ fr_time_res_t

The base resolution for print parse operations.

Enumerator
FR_TIME_RES_INVALID 
FR_TIME_RES_SEC 
FR_TIME_RES_MIN 
FR_TIME_RES_HOUR 
FR_TIME_RES_DAY 
FR_TIME_RES_WEEK 
FR_TIME_RES_MONTH 
FR_TIME_RES_YEAR 
FR_TIME_RES_CSEC 
FR_TIME_RES_MSEC 
FR_TIME_RES_USEC 
FR_TIME_RES_NSEC 

Definition at line 48 of file time.h.

Function Documentation

◆ fr_time()

static fr_time_t fr_time ( void  )
inlinestatic

Return a relative time since the server fr_time_epoch.

This time is useful for doing time comparisons, deltas, etc. Human (i.e. printable) time is something else.

Returns
fr_time_t time in nanoseconds since the server fr_time_epoch.

Definition at line 962 of file time.h.

+ Here is the call graph for this function:

◆ fr_time_add_delta_time()

static fr_time_t fr_time_add_delta_time ( fr_time_delta_t  a,
fr_time_t  b 
)
inlinestatic

Definition at line 180 of file time.h.

+ Here is the call graph for this function:

◆ fr_time_add_time_delta()

static fr_time_t fr_time_add_time_delta ( fr_time_t  a,
fr_time_delta_t  b 
)
inlinestatic

Definition at line 173 of file time.h.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ fr_time_cmp()

static int8_t fr_time_cmp ( fr_time_t  a,
fr_time_t  b 
)
inlinestatic

Compare two fr_time_t values.

Parameters
[in]aThe first value to compare.
[in]bThe second value to compare.
Returns
  • +1 if a > b
  • 0 if a == b
  • -1 if a < b

Definition at line 916 of file time.h.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ fr_time_delta_add()

static fr_time_delta_t fr_time_delta_add ( fr_time_delta_t  a,
fr_time_delta_t  b 
)
inlinestatic

Definition at line 255 of file time.h.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ fr_time_delta_cmp()

static int8_t fr_time_delta_cmp ( fr_time_delta_t  a,
fr_time_delta_t  b 
)
inlinestatic

Compare two fr_time_delta_t values.

Parameters
[in]aThe first value to compare.
[in]bThe second value to compare.
Returns
  • +1 if a > b
  • 0 if a == b
  • -1 if a < b

Definition at line 930 of file time.h.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ fr_time_delta_div()

static fr_time_delta_t fr_time_delta_div ( fr_time_delta_t  a,
fr_time_delta_t  b 
)
inlinestatic

Definition at line 267 of file time.h.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ fr_time_delta_from_csec()

static fr_time_delta_t fr_time_delta_from_csec ( int64_t  csec)
inlinestatic

Definition at line 582 of file time.h.

+ Here is the caller graph for this function:

◆ fr_time_delta_from_integer()

static fr_time_delta_t fr_time_delta_from_integer ( bool overflow,
int64_t  integer,
fr_time_res_t  res 
)
inlinestatic

Definition at line 548 of file time.h.

+ Here is the caller graph for this function:

◆ fr_time_delta_from_msec()

static fr_time_delta_t fr_time_delta_from_msec ( int64_t  msec)
inlinestatic

Definition at line 575 of file time.h.

+ Here is the caller graph for this function:

◆ fr_time_delta_from_nsec()

static fr_time_delta_t fr_time_delta_from_nsec ( int64_t  nsec)
inlinestatic

Definition at line 563 of file time.h.

+ Here is the caller graph for this function:

◆ fr_time_delta_from_sec()

static fr_time_delta_t fr_time_delta_from_sec ( int64_t  sec)
inlinestatic

Definition at line 590 of file time.h.

◆ fr_time_delta_from_str()

fr_slen_t fr_time_delta_from_str ( fr_time_delta_t out,
char const *  in,
size_t  inlen,
fr_time_res_t  hint 
)

Create fr_time_delta_t from a string.

Parameters
[out]outWhere to write fr_time_delta_t
[in]inString to parse.
[in]inlenLength of string.
[in]hintscale for the parsing. Default is "seconds"
Returns
  • >0 on success.
  • <0 on failure.

Definition at line 445 of file time.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ fr_time_delta_from_substr()

fr_slen_t fr_time_delta_from_substr ( fr_time_delta_t out,
fr_sbuff_t in,
fr_time_res_t  hint,
bool  no_trailing,
fr_sbuff_term_t const *  tt 
)

Create fr_time_delta_t from a string.

Parameters
[out]outWhere to write fr_time_delta_t
[in]inString to parse.
[in]hintscale for the parsing. Default is "seconds".
[in]no_trailingasserts that there should be a terminal sequence after the time delta. Allows us to produce better errors.
[in]ttterminal sequences.
Returns
  • >= 0 on success.
  • <0 on failure.

Definition at line 214 of file time.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ fr_time_delta_from_time_zone()

int fr_time_delta_from_time_zone ( char const *  tz,
fr_time_delta_t delta 
)

Return time delta from the time zone.

Returns the delta between UTC and the timezone specified by tz

Parameters
[in]tztime zone name
[out]deltathe time delta
Returns
  • 0 converted OK
  • <0 on error
Note
This function ONLY handles a limited number of time zones: local and gmt. It is impossible in general to parse arbitrary time zone strings, as there are duplicates.

Definition at line 176 of file time.c.

+ Here is the caller graph for this function:

◆ fr_time_delta_from_timespec()

static fr_time_delta_t fr_time_delta_from_timespec ( struct timespec const *  ts)
inlinestatic

Definition at line 614 of file time.h.

+ Here is the caller graph for this function:

◆ fr_time_delta_from_timeval()

static fr_time_delta_t fr_time_delta_from_timeval ( struct timeval const *  tv)
inlinestatic

Definition at line 597 of file time.h.

+ Here is the caller graph for this function:

◆ fr_time_delta_from_usec()

static fr_time_delta_t fr_time_delta_from_usec ( int64_t  usec)
inlinestatic

Definition at line 568 of file time.h.

+ Here is the caller graph for this function:

◆ fr_time_delta_mul()

static fr_time_delta_t fr_time_delta_mul ( fr_time_delta_t  a,
int64_t  b 
)
inlinestatic

Definition at line 273 of file time.h.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ fr_time_delta_sub()

static fr_time_delta_t fr_time_delta_sub ( fr_time_delta_t  a,
fr_time_delta_t  b 
)
inlinestatic

Definition at line 261 of file time.h.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ fr_time_delta_to_csec()

static int64_t fr_time_delta_to_csec ( fr_time_delta_t  delta)
inlinestatic

Definition at line 642 of file time.h.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ fr_time_delta_to_integer()

static int64_t fr_time_delta_to_integer ( fr_time_delta_t  delta,
fr_time_res_t  res 
)
inlinestatic

Definition at line 627 of file time.h.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ fr_time_delta_to_msec()

static int64_t fr_time_delta_to_msec ( fr_time_delta_t  delta)
inlinestatic

Definition at line 637 of file time.h.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ fr_time_delta_to_sec()

static int64_t fr_time_delta_to_sec ( fr_time_delta_t  delta)
inlinestatic

Definition at line 647 of file time.h.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ fr_time_delta_to_str()

fr_slen_t fr_time_delta_to_str ( fr_sbuff_t out,
fr_time_delta_t  delta,
fr_time_res_t  res,
bool  is_unsigned 
)

Print fr_time_delta_t to a string with an appropriate suffix.

Parameters
[out]outWhere to write the string version of the time delta.
[in]deltato print.
[in]resto print resolution with.
[in]is_unsignedwhether the value should be printed unsigned.
Returns
  • >0 the number of bytes written to out.
  • <0 how many additional bytes would have been required.

Definition at line 468 of file time.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ fr_time_delta_to_usec()

static int64_t fr_time_delta_to_usec ( fr_time_delta_t  delta)
inlinestatic

Definition at line 632 of file time.h.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ fr_time_delta_unwrap()

static int64_t fr_time_delta_unwrap ( fr_time_delta_t  time)
inlinestatic

Definition at line 154 of file time.h.

◆ fr_time_elapsed_fprint()

void fr_time_elapsed_fprint ( FILE *  fp,
fr_time_elapsed_t const *  elapsed,
char const *  prefix,
int  tabs 
)

Definition at line 625 of file time.c.

+ Here is the caller graph for this function:

◆ fr_time_elapsed_update()

void fr_time_elapsed_update ( fr_time_elapsed_t elapsed,
fr_time_t  start,
fr_time_t  end 
)

Definition at line 580 of file time.c.

+ Here is the caller graph for this function:

◆ fr_time_from_csec()

static fr_time_t fr_time_from_csec ( int64_t  when)
inlinestatic

Convert csec (wallclock time) to a fr_time_t (internal time)

Parameters
[in]whenThe timestamp to convert.
Returns
  • >0 number of nanoseconds since the server started.
  • 0 when the server started.
  • <0 number of nanoseconds before the server started.

Definition at line 840 of file time.h.

+ Here is the call graph for this function:

◆ fr_time_from_integer()

static fr_time_t fr_time_from_integer ( bool overflow,
int64_t  when,
fr_time_res_t  res 
)
inlinestatic

Convert wallclock time to a fr_time_t (internal time)

Parameters
[out]overflowWhether the conversion overflowed.
[in]whenThe timestamp to convert.
[in]resThe scale the integer value is in.
Returns
  • >0 number of nanoseconds since the server started.
  • 0 when the server started.
  • <0 number of nanoseconds before the server started.

Definition at line 760 of file time.h.

+ Here is the call graph for this function:

◆ fr_time_from_msec()

static fr_time_t fr_time_from_msec ( int64_t  when)
inlinestatic

Convert msec (wallclock time) to a fr_time_t (internal time)

Parameters
[in]whenThe timestamp to convert.
Returns
  • >0 number of nanoseconds since the server started.
  • 0 when the server started.
  • <0 number of nanoseconds before the server started.

Definition at line 822 of file time.h.

+ Here is the call graph for this function:

◆ fr_time_from_nsec()

static fr_time_t fr_time_from_nsec ( int64_t  when)
inlinestatic

Convert a nsec (wallclock time) to a fr_time_t (internal time)

Parameters
[in]whenThe timestamp to convert.
Returns
  • >0 number of nanoseconds since the server started.
  • 0 when the server started.
  • <0 number of nanoseconds before the server started.

Definition at line 786 of file time.h.

+ Here is the call graph for this function:

◆ fr_time_from_sec()

static fr_time_t fr_time_from_sec ( time_t  when)
inlinestatic

Convert a time_t (wallclock time) to a fr_time_t (internal time)

Parameters
[in]whenThe timestamp to convert.
Returns
  • >0 number of nanoseconds since the server started.
  • 0 when the server started.
  • <0 number of nanoseconds before the server started.

Definition at line 858 of file time.h.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ fr_time_from_timespec()

static fr_time_t fr_time_from_timespec ( struct timespec const *  when_ts)
inlinestatic

Convert a timespec (wallclock time) to a fr_time_t (internal time)

Parameters
[in]when_tsThe timestamp to convert.
Returns
  • >0 number of nanoseconds since the server started.
  • 0 when the server started.
  • 0 if when_tv occurred before the server started.

Definition at line 878 of file time.h.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ fr_time_from_timeval()

static fr_time_t fr_time_from_timeval ( struct timeval const *  when_tv)
inlinestatic

Convert a timeval (wallclock time) to a fr_time_t (internal time)

Parameters
[in]when_tvThe timestamp to convert.
Returns
  • >0 number of nanoseconds since the server started.
  • 0 when the server started.
  • <0 number of nanoseconds before the server started.

Definition at line 896 of file time.h.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ fr_time_from_usec()

static fr_time_t fr_time_from_usec ( int64_t  when)
inlinestatic

Convert usec (wallclock time) to a fr_time_t (internal time)

Parameters
[in]whenThe timestamp to convert.
Returns
  • >0 number of nanoseconds since the server started.
  • 0 when the server started.
  • <0 number of nanoseconds before the server started.

Definition at line 804 of file time.h.

+ Here is the call graph for this function:

◆ fr_time_gmtoff()

fr_time_delta_t fr_time_gmtoff ( void  )

Get the offset to gmt.

Definition at line 1231 of file time.c.

+ Here is the caller graph for this function:

◆ fr_time_is_dst()

bool fr_time_is_dst ( void  )

Whether or not we're daylight savings.

Definition at line 1239 of file time.c.

+ Here is the caller graph for this function:

◆ fr_time_offset_to_realtime()

static int64_t fr_time_offset_to_realtime ( void  )
inlinestatic

Return the current value of fr_time_monotonic_to_realtime.

Definition at line 680 of file time.h.

+ Here is the caller graph for this function:

◆ fr_time_op_ispos()

static bool fr_time_op_ispos ( bool  a,
bool  op,
bool  b 
)
static

Definition at line 119 of file time.h.

◆ fr_time_scale()

int64_t fr_time_scale ( int64_t  t,
fr_time_res_t  hint 
)

Scale an input time to NSEC, clamping it at max / min.

Parameters
tinput time / time delta
hinttime resolution hint
Returns
  • INT64_MIN on underflow
  • 0 on invalid hint
  • INT64_MAX on overflow
  • otherwise a valid number, multiplied by the relevant scale, so that the result is in nanoseconds.

Definition at line 716 of file time.c.

+ Here is the caller graph for this function:

◆ fr_time_start()

int fr_time_start ( void  )

Initialize the local time.

MUST be called when the program starts. MUST NOT be called after that.

Returns
  • <0 on error
  • 0 on success

Definition at line 150 of file time.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ fr_time_strftime_local()

size_t fr_time_strftime_local ( fr_sbuff_t out,
fr_time_t  time,
char const *  fmt 
)

Copy a time string (local timezone) to an sbuff.

Note
This function will attempt to extend the sbuff by double the length of the fmt string. It is recommended to either pre-extend the sbuff before calling this function, or avoid using format specifiers that expand to character strings longer than 4 bytes.
Parameters
[in]outWhere to write the formatted time string.
[in]timeInternal server time to convert to wallclock time and copy out as formatted string.
[in]fmtTime format string.
Returns
  • >0 the number of bytes written to the sbuff.
  • 0 if there's insufficient space in the sbuff.

Definition at line 536 of file time.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ fr_time_strftime_utc()

size_t fr_time_strftime_utc ( fr_sbuff_t out,
fr_time_t  time,
char const *  fmt 
)

Copy a time string (UTC) to an sbuff.

Note
This function will attempt to extend the sbuff by double the length of the fmt string. It is recommended to either pre-extend the sbuff before calling this function, or avoid using format specifiers that expand to character strings longer than 4 bytes.
Parameters
[in]outWhere to write the formatted time string.
[in]timeInternal server time to convert to wallclock time and copy out as formatted string.
[in]fmtTime format string.
Returns
  • >0 the number of bytes written to the sbuff.
  • 0 if there's insufficient space in the sbuff.

Definition at line 565 of file time.c.

+ Here is the call graph for this function:

◆ fr_time_sub_time_delta()

static fr_time_t fr_time_sub_time_delta ( fr_time_t  a,
fr_time_delta_t  b 
)
inlinestatic

Definition at line 213 of file time.h.

+ Here is the call graph for this function:

◆ fr_time_sub_time_time()

static fr_time_delta_t fr_time_sub_time_time ( fr_time_t  a,
fr_time_t  b 
)
inlinestatic

Definition at line 207 of file time.h.

+ Here is the call graph for this function:

◆ fr_time_sync()

int fr_time_sync ( void  )

Get a new fr_time_monotonic_to_realtime value.

Should be done regularly to adjust for changes in system time.

Returns
  • 0 on success.
  • -1 on failure.

Definition at line 102 of file time.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ fr_time_to_csec()

static int64_t fr_time_to_csec ( fr_time_t  when)
inlinestatic

Convert an fr_time_t (internal time) to number of csec since the unix epoch (wallclock time)

Definition at line 721 of file time.h.

+ Here is the call graph for this function:

◆ fr_time_to_msec()

static int64_t fr_time_to_msec ( fr_time_t  when)
inlinestatic

Convert an fr_time_t (internal time) to number of msec since the unix epoch (wallclock time)

Definition at line 711 of file time.h.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ fr_time_to_sec()

static int64_t fr_time_to_sec ( fr_time_t  when)
inlinestatic

Convert an fr_time_t (internal time) to number of sec since the unix epoch (wallclock time)

Definition at line 731 of file time.h.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ fr_time_to_unix_time()

static fr_unix_time_t fr_time_to_unix_time ( fr_time_t  when)
inlinestatic

Convert an fr_time_t (internal time) to our version of unix time (wallclock time)

Definition at line 688 of file time.h.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ fr_time_to_usec()

static int64_t fr_time_to_usec ( fr_time_t  when)
inlinestatic

Convert an fr_time_t (internal time) to number of usec since the unix epoch (wallclock time)

Definition at line 701 of file time.h.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ fr_time_unwrap()

static int64_t fr_time_unwrap ( fr_time_t  time)
inlinestatic

Definition at line 146 of file time.h.

+ Here is the caller graph for this function:

◆ fr_unix_time_add_delta_time()

static fr_unix_time_t fr_unix_time_add_delta_time ( fr_time_delta_t  a,
fr_unix_time_t  b 
)
inlinestatic

Definition at line 308 of file time.h.

+ Here is the call graph for this function:

◆ fr_unix_time_add_time_delta()

static fr_unix_time_t fr_unix_time_add_time_delta ( fr_unix_time_t  a,
fr_time_delta_t  b 
)
inlinestatic

Definition at line 302 of file time.h.

+ Here is the call graph for this function:

◆ fr_unix_time_cmp()

static int8_t fr_unix_time_cmp ( fr_unix_time_t  a,
fr_unix_time_t  b 
)
inlinestatic

Compare two fr_unix_time_t values.

Parameters
[in]aThe first value to compare.
[in]bThe second value to compare.
Returns
  • +1 if a > b
  • 0 if a == b
  • -1 if a < b

Definition at line 944 of file time.h.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ fr_unix_time_from_csec()

static fr_unix_time_t fr_unix_time_from_csec ( int64_t  csec)
inlinestatic

Definition at line 442 of file time.h.

◆ fr_unix_time_from_integer()

static fr_unix_time_t fr_unix_time_from_integer ( bool overflow,
int64_t  integer,
fr_time_res_t  res 
)
inlinestatic

Definition at line 411 of file time.h.

+ Here is the caller graph for this function:

◆ fr_unix_time_from_msec()

static fr_unix_time_t fr_unix_time_from_msec ( int64_t  msec)
inlinestatic

Definition at line 435 of file time.h.

◆ fr_unix_time_from_nsec()

static fr_unix_time_t fr_unix_time_from_nsec ( int64_t  nsec)
inlinestatic

Definition at line 423 of file time.h.

+ Here is the caller graph for this function:

◆ fr_unix_time_from_sec()

static fr_unix_time_t fr_unix_time_from_sec ( int64_t  sec)
inlinestatic

Definition at line 449 of file time.h.

+ Here is the caller graph for this function:

◆ fr_unix_time_from_str()

int fr_unix_time_from_str ( fr_unix_time_t date,
char const *  date_str,
fr_time_res_t  hint 
)

Convert string in various formats to a fr_unix_time_t.

Parameters
date_strinput date string.
datetime_t to write result to.
[in]hintscale for the parsing. Default is "seconds"
Returns
  • 0 on success.
  • -1 on failure.

Definition at line 827 of file time.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ fr_unix_time_from_time()

static fr_unix_time_t fr_unix_time_from_time ( time_t  time)
inlinestatic

Convert a time_t into out internal fr_unix_time_t.

Our internal unix time representation is unsigned and in nanoseconds which is different from time_t which is signed and has seconds resolution.

If time is negative we return 0.

Parameters
[in]timeto convert.
Returns
Unix time in seconds.

Definition at line 536 of file time.h.

◆ fr_unix_time_from_timespec()

static fr_unix_time_t fr_unix_time_from_timespec ( struct timespec const *  ts)
inlinestatic

Definition at line 473 of file time.h.

◆ fr_unix_time_from_timeval()

static fr_unix_time_t fr_unix_time_from_timeval ( struct timeval const *  tv)
inlinestatic

Definition at line 456 of file time.h.

◆ fr_unix_time_from_tm()

fr_unix_time_t fr_unix_time_from_tm ( struct tm *  tm)

Definition at line 661 of file time.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ fr_unix_time_from_usec()

static fr_unix_time_t fr_unix_time_from_usec ( int64_t  usec)
inlinestatic

Definition at line 428 of file time.h.

◆ fr_unix_time_sub_time_delta()

static fr_unix_time_t fr_unix_time_sub_time_delta ( fr_unix_time_t  a,
fr_time_delta_t  b 
)
inlinestatic

Definition at line 341 of file time.h.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ fr_unix_time_sub_time_time()

static fr_time_delta_t fr_unix_time_sub_time_time ( fr_unix_time_t  a,
fr_unix_time_t  b 
)
inlinestatic

Definition at line 335 of file time.h.

+ Here is the call graph for this function:

◆ fr_unix_time_to_csec()

static int64_t fr_unix_time_to_csec ( fr_unix_time_t  delta)
inlinestatic

Definition at line 501 of file time.h.

+ Here is the call graph for this function:

◆ fr_unix_time_to_day()

static int64_t fr_unix_time_to_day ( fr_unix_time_t  delta)
inlinestatic

Definition at line 521 of file time.h.

+ Here is the call graph for this function:

◆ fr_unix_time_to_hour()

static int64_t fr_unix_time_to_hour ( fr_unix_time_t  delta)
inlinestatic

Definition at line 516 of file time.h.

+ Here is the call graph for this function:

◆ fr_unix_time_to_integer()

static int64_t fr_unix_time_to_integer ( fr_unix_time_t  delta,
fr_time_res_t  res 
)
inlinestatic

Definition at line 486 of file time.h.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ fr_unix_time_to_min()

static int64_t fr_unix_time_to_min ( fr_unix_time_t  delta)
inlinestatic

Definition at line 511 of file time.h.

+ Here is the call graph for this function:

◆ fr_unix_time_to_msec()

static int64_t fr_unix_time_to_msec ( fr_unix_time_t  delta)
inlinestatic

Definition at line 496 of file time.h.

+ Here is the call graph for this function:

◆ fr_unix_time_to_sec()

static int64_t fr_unix_time_to_sec ( fr_unix_time_t  delta)
inlinestatic

Definition at line 506 of file time.h.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ fr_unix_time_to_str()

fr_slen_t fr_unix_time_to_str ( fr_sbuff_t out,
fr_unix_time_t  time,
fr_time_res_t  res,
bool  utc 
)

Convert unix time to string.

Parameters
[out]outWhere to write the string.
[in]timeto convert.
[in]resWhat base resolution to print the time as.
Returns
  • 0 on success.
  • -1 on failure.

Definition at line 1154 of file time.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ fr_unix_time_to_usec()

static int64_t fr_unix_time_to_usec ( fr_unix_time_t  delta)
inlinestatic

Definition at line 491 of file time.h.

+ Here is the call graph for this function:

◆ fr_unix_time_unwrap()

static uint64_t fr_unix_time_unwrap ( fr_unix_time_t  time)
inlinestatic

Definition at line 161 of file time.h.

+ Here is the caller graph for this function:

Variable Documentation

◆ fr_time_epoch

int64_t fr_time_epoch
extern

monotonic clock at boot, i.e. our epoch

Definition at line 86 of file time.c.

◆ fr_time_monotonic_to_realtime

_Atomic int64_t fr_time_monotonic_to_realtime
extern

difference between the two clocks

Definition at line 87 of file time.c.

◆ fr_time_multiplier_by_res

int64_t const fr_time_multiplier_by_res[]
extern

Definition at line 32 of file time.c.

◆ fr_time_precision_table

fr_table_num_ordered_t const fr_time_precision_table[]
extern

Definition at line 46 of file time.c.

◆ fr_time_precision_table_len

size_t fr_time_precision_table_len
extern

Definition at line 84 of file time.c.