Functions that work with C and C++ time types.
More...
Functions that work with C and C++ time types.
You can define UTIL_TIME_INCLUDE_TIMEVAL to include timeval conversion functions. Since these are defined in sys/time.h on POSIX systems, embedded devices may not have them, so we do not use them by default.
Time conversionf unctions were inspired by this post on StackOverflow: https://stackoverflow.com/questions/31409036/converting-from-struct-timespec-to-stdchrono
◆ durationToTimespec()
| constexpr timespec embutil::durationToTimespec |
( |
std::chrono::nanoseconds |
dur | ) |
|
|
noexcept |
Convert from std::chrono::duration to struct timespec.
- Parameters
-
| [in] | dur | std::chrono::duration value, which can be relative or absolute. |
- Returns
- the equivalent struct timespec value.
◆ timepointToTimespec()
| constexpr timespec embutil::timepointToTimespec |
( |
std::chrono::time_point< std::chrono::system_clock, std::chrono::nanoseconds > |
tp | ) |
|
|
noexcept |
Convert from std::chrono::time_point to struct timespec.
- Parameters
-
| [in] | tp | std::chrono::time_point value using the system_clock. |
- Returns
- the equivalent struct timespec value.
Referenced by os::posix::ConditionVariable::wait().
◆ timespecToDuration()
| constexpr std::chrono::nanoseconds embutil::timespecToDuration |
( |
const timespec |
ts | ) |
|
|
noexcept |
◆ timespecToTimePoint()
| constexpr std::chrono::time_point<std::chrono::system_clock, std::chrono::nanoseconds> embutil::timespecToTimePoint |
( |
const timespec |
ts | ) |
|
|
noexcept |
Convert from struct timespec to std::chrono::time_point.
- Parameters
-
| [in] | ts | Timespec value, which can be relative or absolute. |
- Returns
- the equivalent std::chrono::time_point value using the system_clock.
References embutil::timespecToDuration().