Base module

time

Classes and functions for handling time.

Functions

ReturnNameDescription
std::time_tnowReturns the current wall-clock time as a UTC time_t (seconds since epoch).
doubleclockSecsReturns the elapsed process time in decimal seconds using a monotonic clock.
std::stringprintFormats a broken-down time value using the given strftime format string.
std::stringprintLocalFormats the current local time using the given strftime format string.
std::stringprintUTCFormats the current UTC time using the given strftime format string.
std::tmtoLocalConverts a time_t value to a broken-down local time structure. Uses thread-safe native functions (localtime_r / localtime_s).
std::tmtoUTCConverts a time_t value to a broken-down UTC time structure. Uses thread-safe native functions (gmtime_r / gmtime_s).
std::stringgetLocalReturns the current local time as an ISO8601 formatted string.
std::stringgetUTCReturns the current UTC time as an ISO8601 formatted string.
uint64_thrtimeReturns the current high-resolution monotonic time in nanoseconds.

now

std::time_t now()

Defined in src/base/include/icy/time.h:48

Returns the current wall-clock time as a UTC time_t (seconds since epoch).

Returns

Current UTC time in seconds since the Unix epoch.


clockSecs

double clockSecs()

Defined in src/base/include/icy/time.h:52

Returns the elapsed process time in decimal seconds using a monotonic clock.

Returns

Process time in seconds.


print

std::string print(const std::tm & dt, const char * fmt = ISO8601Format)

Defined in src/base/include/icy/time.h:58

Formats a broken-down time value using the given strftime format string.

Returns

Formatted time string.

Parameters

ParameterTypeDescription
dtconst std::tm &Broken-down time to format.
fmtconst char *strftime format string (default: ISO8601Format).

printLocal

std::string printLocal(const char * fmt = ISO8601Format)

Defined in src/base/include/icy/time.h:63

Formats the current local time using the given strftime format string.

Returns

Formatted local time string.

Parameters

ParameterTypeDescription
fmtconst char *strftime format string (default: ISO8601Format).

printUTC

std::string printUTC(const char * fmt = ISO8601Format)

Defined in src/base/include/icy/time.h:68

Formats the current UTC time using the given strftime format string.

Returns

Formatted UTC time string.

Parameters

ParameterTypeDescription
fmtconst char *strftime format string (default: ISO8601Format).

toLocal

std::tm toLocal(const std::time_t & time)

Defined in src/base/include/icy/time.h:74

Converts a time_t value to a broken-down local time structure. Uses thread-safe native functions (localtime_r / localtime_s).

Returns

Broken-down local time.

Parameters

ParameterTypeDescription
timeconst std::time_t &UTC time value to convert.

toUTC

std::tm toUTC(const std::time_t & time)

Defined in src/base/include/icy/time.h:80

Converts a time_t value to a broken-down UTC time structure. Uses thread-safe native functions (gmtime_r / gmtime_s).

Returns

Broken-down UTC time.

Parameters

ParameterTypeDescription
timeconst std::time_t &UTC time value to convert.

getLocal

std::string getLocal()

Defined in src/base/include/icy/time.h:84

Returns the current local time as an ISO8601 formatted string.

Returns

ISO8601 local time string.


getUTC

std::string getUTC()

Defined in src/base/include/icy/time.h:88

Returns the current UTC time as an ISO8601 formatted string.

Returns

ISO8601 UTC time string.


hrtime

uint64_t hrtime()

Defined in src/base/include/icy/time.h:92

Returns the current high-resolution monotonic time in nanoseconds.

Returns

Current time in nanoseconds (suitable for measuring intervals).

Variables

ReturnNameDescription
const int64_tkNumMillisecsPerSec staticConstants for calculating time.
const int64_tkNumMicrosecsPerSec static
const int64_tkNumNanosecsPerSec static
const int64_tkNumMicrosecsPerMillisec static
const int64_tkNumNanosecsPerMillisec static
const int64_tkNumNanosecsPerMicrosec static
const char *ISO8601Format staticThe date/time format defined in the ISO 8601 standard. This is the default format used throughout the library for consistency.

kNumMillisecsPerSec

static

const int64_t kNumMillisecsPerSec = INT64_C(1000)

Defined in src/base/include/icy/time.h:30

Constants for calculating time.


kNumMicrosecsPerSec

static

const int64_t kNumMicrosecsPerSec = INT64_C(1000000)

Defined in src/base/include/icy/time.h:31


kNumNanosecsPerSec

static

const int64_t kNumNanosecsPerSec = INT64_C(1000000000)

Defined in src/base/include/icy/time.h:32


kNumMicrosecsPerMillisec

static

const int64_t kNumMicrosecsPerMillisec = kNumMicrosecsPerSec / kNumMillisecsPerSec

Defined in src/base/include/icy/time.h:34


kNumNanosecsPerMillisec

static

const int64_t kNumNanosecsPerMillisec = kNumNanosecsPerSec / kNumMillisecsPerSec

Defined in src/base/include/icy/time.h:35


kNumNanosecsPerMicrosec

static

const int64_t kNumNanosecsPerMicrosec = kNumNanosecsPerSec / kNumMicrosecsPerSec

Defined in src/base/include/icy/time.h:36


ISO8601Format

static

const char * ISO8601Format = "%Y-%m-%dT%H:%M:%SZ"

Defined in src/base/include/icy/time.h:44

The date/time format defined in the ISO 8601 standard. This is the default format used throughout the library for consistency.

Examples: 2005-01-01T12:00:00+01:00 2005-01-01T11:00:00Z