Class Duration

Class Documentation

class Duration

Duration represents a time interval and -

  • Can be incremented by durations expressed as seconds, nanoseconds milliseconds, or Duration objects.

  • Can be converted to and from Durations expressed in milliseconds (or other units) as integer types.

Public Functions

Duration()

Create a Duration elapsing the default amount of time (zero seconds).

explicit Duration(int32_t sec, uint32_t nanosec = 0)

Create a Duration elapsing a specific amount of time.

Parameters
  • sec – Amount of seconds for the Duration.

  • nanosec – Amount of nanoseconds for the Duration.

int64_t sec() const

Get seconds part of the Duration.

Returns

number of seconds

void sec(int64_t s)

Set number of seconds

Parameters

s – number of seconds

uint32_t nanosec() const

Get nanoseconds part of the Duration.

Returns

number of nanoseconds

void nanosec(uint32_t ns)

Set number of nanoseconds

Parameters

ns – number of nanoseconds

int compare(const Duration &that) const

Returns an integer value for a comparison of two Durations: 1 if this Duration is greater than the comparator (that) -1 if the Duration is less than the comparator (that) 0 if the Duration matches the comparator (that)

Parameters

thatDuration to compare

Returns

comparison result

bool operator>(const Duration &that) const

Returns true if the Duration is greater than the comparator

Parameters

thatDuration to compare

Returns

comparison result

bool operator>=(const Duration &that) const

Returns true if the Duration is greater than or equal to the comparator

Parameters

Duration – &that

bool operator!=(const Duration &that) const

Returns true if the Duration is not equal to the comparator

Parameters

thatDuration to compare

Returns

comparison result

bool operator==(const Duration &that) const

Returns true if the Duration is equal to the comparator

Parameters

thatDuration to compare

Returns

comparison result

bool operator<=(const Duration &that) const

Returns true if the Duration is less than or equal to the comparator

Parameters

thatDuration to compare

Returns

comparison result

bool operator<(const Duration &that) const

Returns true if the Duration is less than the comparator

Parameters

thatDuration to compare

Returns

comparison result

Duration &operator+=(const Duration &a_ti)

Add a Duration to this Duration

Parameters

a_tiDuration to add

Returns

this Duration + a_ti

Duration &operator-=(const Duration &a_ti)

Subtract a Duration from this Duration

Parameters

a_tiDuration to subtract

Returns

this Duration - a_ti

Duration &operator*=(uint64_t factor)

Multiply this Duration by a factor

Parameters

factor – the factor to multiply this Duration by

Returns

this Duration * factor

const Duration operator+(const Duration &other) const

Add a Duration to Duration

Parameters

other – a Duration

Returns

Duration + other

const Duration operator-(const Duration &other) const

Subtract a Duration from Duration

Parameters

other – a Duration

Returns

the Duration - other

int64_t to_millisecs() const

Returns this Duration in milliseconds.

Returns

the duration in milliseconds

int64_t to_microsecs() const

Returns this Duration in micro-seconds.

Returns

the duration in micro-seconds

double to_secs() const

Returns this Duration in seconds.

Returns

the duration in seconds

Public Static Functions

static const Duration zero()

Create a Duration elapsing zero seconds.

static const Duration infinite()

Create an infinite Duration.

static const Duration from_microsecs(int64_t microseconds)

Create a Duration from a number of microseconds

Parameters

microseconds – number of microseconds

static const Duration from_millisecs(int64_t milliseconds)

Create a Duration from a number of milliseconds

Parameters

miliseconds – number of milliseconds

static const Duration from_secs(double seconds)

Create a Duration from a number of seconds

Parameters

seconds – number of seconds