absl::DurationFromTimespec

Converts a timespec to an absl::Duration.

Synopsis

Declared in <absl/time/time.h>

Duration
DurationFromTimespec(timespec ts);

Description

Some APIs use a timespec or a timeval as a Duration (e.g., nanosleep(2) and select(2)), while others use them as a Time (e.g. clock_gettime(2) and gettimeofday(2)), so conversion functions are provided for both cases. The "to timespec/val" direction is easily handled via overloading, but for "from timespec/val" the desired type is part of the function name.

Return Value

The equivalent duration.

Parameters

NameDescription
tsThe timespec to convert.