#include "xroad_common_types.h"
#include "xroad_string.h"
#include "xroad_tzone.h"
#include <stdint.h>
#include <time.h>
#include <sys/time.h>
Go to the source code of this file.
|
xroad_time_t | xroad_time_create (uint8_t hour, uint8_t min, uint8_t sec, uint32_t usec, xroad_tzone_t tz) |
|
bool | xroad_time_is_null (xroad_time_t time) |
|
xroad_time_t | xroad_time_from_str (xroad_str_t time) |
|
int64_t | xroad_time_cmp (xroad_time_t lhs, xroad_time_t rhs) |
|
xroad_time_t | xroad_time_min (xroad_time_t a, xroad_time_t b) |
|
xroad_time_t | xroad_time_max (xroad_time_t a, xroad_time_t b) |
|
int64_t | xroad_time_to_usec (xroad_time_t time) |
|
xroad_time_t | xroad_time_from_ts (xroad_timestamp_t ts, xroad_tzone_t tz) |
|
xroad_timestamp_t | xroad_time_to_ts (xroad_time_t time) |
|
xroad_time_t | xroad_time_now (xroad_tzone_t tz) |
|
xroad_time_t | xroad_time_change_tz (xroad_time_t tm, xroad_tzone_t new_tz) |
|
int64_t | xroad_time_distance (xroad_time_t a, xroad_time_t b) |
|
xroad_time_t | xroad_time_adjust (xroad_time_t time, int64_t usec) |
|
xroad_timestamp_t | xroad_now () |
|
xroad_timestamp_t | xroad_now_nano () |
|
xroad_timestamp_t | xroad_now_sec () |
|
xroad_timestamp_t | xroad_now_monotonic (void) |
|
int64_t | xroad_time_start_of_day (time_t now) |
|
◆ xroad_time_to_sql
#define xroad_time_to_sql |
( |
|
v | ) |
|
Value:({ \
char* buf = "NULL"; \
uint32_t len = 4; \
xroad_time_t dt = (v); \
{ \
buf = alloca(s.len + 2); \
buf[0] = '\''; \
memcpy(buf + 1, s.data, s.len); \
buf[s.len + 1] = '\''; \
len = s.len + 2; \
} \
xroad_str_len(buf, len); \
})
#define xroad_time_to_str(tm)
Definition: xroad_time.h:64
bool xroad_time_is_null(xroad_time_t time)
convert xroad_time_t to SQL string representation (NULL, '10:10:10')
- Parameters
-
- Returns
- SQL string
◆ xroad_time_to_str
#define xroad_time_to_str |
( |
|
tm | ) |
|
Value:({ \
char* buff = (char*)alloca(64); \
buff, 64, "%02d:%02d:%02d", tm.hour, tm.min, tm.sec); \
if (tm.usec) \
{ \
} \
if (tm.tz > 0) \
{ \
} \
xroad_str_len(buff, s); \
})
xroad_str_t xroad_tzone_get_name(xroad_tzone_t idx)
convert time with timezone to string
- Parameters
-
- Returns
- string representation
◆ xroad_now()
xroad_timestamp_t xroad_now |
( |
| ) |
|
- Returns
- now timestamp in microseconds
◆ xroad_now_monotonic()
xroad_timestamp_t xroad_now_monotonic |
( |
void |
| ) |
|
return monotonic time as clock_gettime(CLOCK_MONOTONIC_RAW)
- Returns
- monotonic timestamp
◆ xroad_now_nano()
xroad_timestamp_t xroad_now_nano |
( |
| ) |
|
- Returns
- now timestamp in nanoseconds
◆ xroad_now_sec()
xroad_timestamp_t xroad_now_sec |
( |
| ) |
|
- Returns
- now timestamp in seconds
◆ xroad_time_adjust()
adjust time to N microseconds
- Parameters
-
[in] | time | - time to adjust |
[in] | usec | - microseconds (can be negative) |
- Returns
- adjusted time
◆ xroad_time_change_tz()
change time timezone
- Parameters
-
[in] | tm | - time to change |
[in] | new_tz | - new timezone |
- Returns
- time with new timezone
◆ xroad_time_cmp()
compare two time values
- Parameters
-
[in] | lhs | - left time value |
[in] | rhs | - right time value |
- Returns
- 0 - lhs == rhs, >0 - lhs > rhs, <0 - lhs < rhs
◆ xroad_time_create()
xroad_time_t xroad_time_create |
( |
uint8_t |
hour, |
|
|
uint8_t |
min, |
|
|
uint8_t |
sec, |
|
|
uint32_t |
usec, |
|
|
xroad_tzone_t |
tz |
|
) |
| |
create time
- Parameters
-
[in] | hour | - hour (0-24) |
[in] | min | - minute (0-59) |
[in] | sec | - second (0-59) |
[in] | usec | - microseconds |
[in] | tz | - tmezone, if any |
- Returns
- xroad_time_t
◆ xroad_time_distance()
calculate difference between times, expressed in microseconds
- Parameters
-
[in] | a | - time from |
[in] | b | - time to return distance in microseconds |
◆ xroad_time_from_str()
create time from string in format HH:MM:SS.UUUUUU
- Parameters
-
- Returns
- xroad_time_t instance
◆ xroad_time_from_ts()
xroad_time_t xroad_time_from_ts |
( |
xroad_timestamp_t |
ts, |
|
|
xroad_tzone_t |
tz |
|
) |
| |
get time from timestamp
- Parameters
-
[in] | time | - time to convert |
[in] | tz | - timezone |
- Returns
- microseconds
◆ xroad_time_is_null()
check if time is null
- Parameters
-
- Returns
- true if time is null
◆ xroad_time_max()
return maximum time of a and b
- Parameters
-
- Returns
- maximum value
◆ xroad_time_min()
return minimum time of a and b
- Parameters
-
- Returns
- minimum value
◆ xroad_time_now()
get current time
- Parameters
-
[in] | tz | - timezone. If 0, current tz used |
- Returns
- current time
◆ xroad_time_start_of_day()
int64_t xroad_time_start_of_day |
( |
time_t |
now | ) |
|
- Parameters
-
[in] | now | - timestamp in seconds, if NULL current timestamp will be given |
- Returns
- EPOCH seconds to the begin of the current day
◆ xroad_time_to_ts()
convert time to timestamp using current date
- Parameters
-
[in] | time | - time to convert |
- Returns
- timestamp
◆ xroad_time_to_usec()
convert time to microseconds
- Parameters
-
[in] | time | - time to convert |
- Returns
- microseconds