Zephyr API Documentation 4.2.99
A Scalable Open Source RTOS
Loading...
Searching...
No Matches
Time Representation APIs

Macros

#define TIME_UTILS_BASE_YEAR   1900

Functions

int64_t timeutil_timegm64 (const struct tm *tm)
 Convert broken-down time to a POSIX epoch offset in seconds.
time_t timeutil_timegm (const struct tm *tm)
 Convert broken-down time to a POSIX epoch offset in seconds.
static void timespec_from_timeout (k_timeout_t timeout, struct timespec *ts)
 Convert a kernel timeout to a timespec.
static k_timeout_t timespec_to_timeout (const struct timespec *req, struct timespec *rem)
 Convert a timespec to a kernel timeout.

Detailed Description

Macro Definition Documentation

◆ TIME_UTILS_BASE_YEAR

#define TIME_UTILS_BASE_YEAR   1900

Function Documentation

◆ timespec_from_timeout()

void timespec_from_timeout ( k_timeout_t timeout,
struct timespec * ts )
inlinestatic

#include <zephyr/sys/timeutil.h>

Convert a kernel timeout to a timespec.

This function converts time durations expressed as Zephyr k_timeout_t objects to struct timespec objects.

Note
This function will assert if assertions are enabled and timeout is not relative, (i.e. a timeout generated by K_TIMEOUT_ABS_TICKS or similar is used).
Parameters
timeoutthe kernel timeout to convert
[out]tsthe timespec to store the result

◆ timespec_to_timeout()

k_timeout_t timespec_to_timeout ( const struct timespec * req,
struct timespec * rem )
inlinestatic

#include <zephyr/sys/timeutil.h>

Convert a timespec to a kernel timeout.

This function converts a time duration, req, expressed as a timespec object, to a Zephyr k_timeout_t object.

If req contains a negative duration or if both tv_sec and tv_nsec fields are zero, this function will return K_NO_WAIT.

If req contains the maximum representable timespec, {max(time_t), 999999999}, then this function will return K_FOREVER.

If req contains a value that is greater than the maximum equivalent tick duration, then this function will return the maximum representable tick duration (i.e. req will be rounded-down).

Otherwise, this function will return the k_timeout_t that is rounded-up to a tick boundary.

If rem is not NULL, it will be set to the remainder of the conversion, i.e. the difference between the requested duration and the converted duration as a timespec object, approximately as shown below.

rem = requested_duration - converted_duration
Parameters
reqthe requested timespec to convert
[out]remoptional pointer to a timespec to store the remainder
Returns
the corresponding kernel timeout

◆ timeutil_timegm()

time_t timeutil_timegm ( const struct tm * tm)

#include <zephyr/sys/timeutil.h>

Convert broken-down time to a POSIX epoch offset in seconds.

Parameters
tmpointer to broken down time.
Returns
the corresponding time in the POSIX epoch time scale. If the time cannot be represented then (time_t)-1 is returned and errno is set to ERANGE`.
See also
http://man7.org/linux/man-pages/man3/timegm.3.html

◆ timeutil_timegm64()

int64_t timeutil_timegm64 ( const struct tm * tm)

#include <zephyr/sys/timeutil.h>

Convert broken-down time to a POSIX epoch offset in seconds.

Parameters
tmpointer to broken down time.
Returns
the corresponding time in the POSIX epoch time scale.
See also
http://man7.org/linux/man-pages/man3/timegm.3.html