UniRec  2.9.3
Macros | Typedefs | Functions
Timestamps API

Macros

#define UR_TIME_NSEC_TO_FRAC   0x44B82FA0AULL
 
#define ur_time_from_sec_nsec(sec, nsec)   (ur_time_t) (((uint64_t) (sec) << 32) | (((uint64_t) (nsec) * UR_TIME_NSEC_TO_FRAC) >> 32))
 Convert seconds and nanoseconds to ur_time_t. More...
 
#define ur_time_from_sec_usec(sec, usec)   (ur_time_t) (((uint64_t) (sec) << 32) | (((uint64_t) (usec) * 1000 * UR_TIME_NSEC_TO_FRAC) >> 32))
 Convert seconds and microseconds to ur_time_t. More...
 
#define ur_time_from_sec_msec(sec, msec)   (ur_time_t) (((uint64_t) (sec) << 32) | (((uint64_t) (msec) * 1000000 * UR_TIME_NSEC_TO_FRAC) >> 32))
 Convert seconds and milliseconds to ur_time_t. More...
 
#define ur_time_get_sec(time)   (uint32_t) ((uint64_t) (time) >> 32)
 Get number of seconds from ur_time_t. More...
 
#define ur_time_get_nsec(time)   (uint32_t) ((((uint64_t) (time) & 0xffffffff) * 1000000000ULL + 0xffffffff) >> 32)
 Get number of nanoseconds from ur_time_t. More...
 
#define ur_time_get_usec(time)   (uint32_t) (ur_time_get_nsec(time) / 1000)
 Get number of microeconds from ur_time_t. More...
 
#define ur_time_get_msec(time)   (uint32_t) (ur_time_get_nsec(time) / 1000000)
 Get number of milliseconds from ur_time_t. More...
 

Typedefs

typedef uint64_t ur_time_t
 Type of timestamps used in UniRec Timestamps in UniRec are stored as number of seconds from Unix epoch in 64bit fixed point number (32bit integral part, 32bit fraction part). More...
 

Functions

static uint64_t ur_timediff (ur_time_t a, ur_time_t b)
 
static uint64_t ur_timediff_us (ur_time_t a, ur_time_t b)
 
static uint64_t ur_timediff_ns (ur_time_t a, ur_time_t b)
 
uint8_t ur_time_from_string (ur_time_t *ur, const char *str)
 

Detailed Description

Macro Definition Documentation

◆ ur_time_from_sec_msec

#define ur_time_from_sec_msec (   sec,
  msec 
)    (ur_time_t) (((uint64_t) (sec) << 32) | (((uint64_t) (msec) * 1000000 * UR_TIME_NSEC_TO_FRAC) >> 32))

Convert seconds and milliseconds to ur_time_t.

Parameters
secseconds
msecmilliseconds
Returns
UniRec timestamp (ur_time_t)

Definition at line 116 of file ur_time.h.

◆ ur_time_from_sec_nsec

#define ur_time_from_sec_nsec (   sec,
  nsec 
)    (ur_time_t) (((uint64_t) (sec) << 32) | (((uint64_t) (nsec) * UR_TIME_NSEC_TO_FRAC) >> 32))

Convert seconds and nanoseconds to ur_time_t.

Parameters
secseconds
nsecnanoseconds
Returns
UniRec timestamp (ur_time_t)

Definition at line 100 of file ur_time.h.

◆ ur_time_from_sec_usec

#define ur_time_from_sec_usec (   sec,
  usec 
)    (ur_time_t) (((uint64_t) (sec) << 32) | (((uint64_t) (usec) * 1000 * UR_TIME_NSEC_TO_FRAC) >> 32))

Convert seconds and microseconds to ur_time_t.

Parameters
secseconds
usecmicroseconds
Returns
UniRec timestamp (ur_time_t)

Definition at line 108 of file ur_time.h.

◆ ur_time_get_msec

#define ur_time_get_msec (   time)    (uint32_t) (ur_time_get_nsec(time) / 1000000)

Get number of milliseconds from ur_time_t.

Parameters
timeUniRec timestamp
Returns
milliseconds

Definition at line 146 of file ur_time.h.

◆ ur_time_get_nsec

#define ur_time_get_nsec (   time)    (uint32_t) ((((uint64_t) (time) & 0xffffffff) * 1000000000ULL + 0xffffffff) >> 32)

Get number of nanoseconds from ur_time_t.

Parameters
timeUniRec timestamp
Returns
nanoseconds

Definition at line 132 of file ur_time.h.

◆ ur_time_get_sec

#define ur_time_get_sec (   time)    (uint32_t) ((uint64_t) (time) >> 32)

Get number of seconds from ur_time_t.

Parameters
timeUniRec timestamp
Returns
seconds

Definition at line 124 of file ur_time.h.

◆ ur_time_get_usec

#define ur_time_get_usec (   time)    (uint32_t) (ur_time_get_nsec(time) / 1000)

Get number of microeconds from ur_time_t.

Parameters
timeUniRec timestamp
Returns
microseconds

Definition at line 139 of file ur_time.h.

◆ UR_TIME_NSEC_TO_FRAC

#define UR_TIME_NSEC_TO_FRAC   0x44B82FA0AULL

Constant used to convert nanoseconds to fraction of second on 32 bits. Its value is 2^32/1e9 in fixed-point notation, which is (2^32/1e9)*2^32 = 2^64/1e9 (rounded).

Definition at line 67 of file ur_time.h.

Typedef Documentation

◆ ur_time_t

typedef uint64_t ur_time_t

Type of timestamps used in UniRec Timestamps in UniRec are stored as number of seconds from Unix epoch in 64bit fixed point number (32bit integral part, 32bit fraction part).

Definition at line 61 of file ur_time.h.

Function Documentation

◆ ur_time_from_string()

uint8_t ur_time_from_string ( ur_time_t ur,
const char *  str 
)

Convert string value str into UniRec time ur.

Parameters
[out]urTarget pointer to store result.
[in]strString in the following format: 2018-06-27T16:52:54 or 2018-06-27T16:52:54.500, str may end with "Z" (2018-06-27T16:52:54Z or 2018-06-27T16:52:54.500Z) indicating UTC timezone explicitly. UTC is recommended and should be used in any case.
Returns
0 on success, 1 is returned on parsing error (malformed format of str) and ur is set to 0, 2 on bad parameter (NULL was passed).

Definition at line 1606 of file unirec.c.

◆ ur_timediff()

static uint64_t ur_timediff ( ur_time_t  a,
ur_time_t  b 
)
inlinestatic

Return a time difference between A and B in miliseconds.

Parameters
[in]aTimestamp A
[in]bTimestamp B
Returns
abs(A - B), the result is in miliseconds.

Definition at line 157 of file ur_time.h.

◆ ur_timediff_ns()

static uint64_t ur_timediff_ns ( ur_time_t  a,
ur_time_t  b 
)
inlinestatic

Return a time difference between A and B in nanoseconds.

Parameters
[in]aTimestamp A
[in]bTimestamp B
Returns
abs(A - B), the result is in nanoseconds.

Definition at line 183 of file ur_time.h.

◆ ur_timediff_us()

static uint64_t ur_timediff_us ( ur_time_t  a,
ur_time_t  b 
)
inlinestatic

Return a time difference between A and B in microseconds.

Parameters
[in]aTimestamp A
[in]bTimestamp B
Returns
abs(A - B), the result is in microseconds.

Definition at line 170 of file ur_time.h.