Class Duration

Class Documentation

class Duration

Represents a duration with millisecond resolution.

Arithmetic operators

Duration operator+(const Duration &rhs) const noexcept

Performs addition.

Parameters:

rhs[in] Right-hand side of the operation.

Returns:

Result of the operation.

Duration &operator+=(const Duration &rhs) noexcept

Performs addition.

Parameters:

rhs[in] Right-hand side of the operation.

Returns:

This duration.

Duration operator-(const Duration &rhs) const noexcept

Performs subtraction.

Parameters:

rhs[in] Right-hand side of the operation.

Returns:

Result of the operation.

Duration &operator-=(const Duration &rhs) noexcept

Performs subtraction.

Parameters:

rhs[in] Right-hand side of the operation.

Returns:

This duration.

Duration operator*(uint64_t rhs) const noexcept

Performs multiplication.

Parameters:

rhs[in] Right-hand side of the operation.

Returns:

Result of the operation.

Duration &operator*=(uint64_t rhs) noexcept

Performs multiplication.

Parameters:

rhs[in] Right-hand side of the operation.

Returns:

This duration.

uint64_t operator/(const Duration &rhs) const noexcept

Performs division.

Parameters:

rhs[in] Right-hand side of the operation.

Returns:

Result of the operation.

Duration operator/(uint64_t rhs) const noexcept

Performs division.

Parameters:

rhs[in] Right-hand side of the operation.

Returns:

Result of the operation.

Duration &operator/=(uint64_t rhs) noexcept

Performs division.

Parameters:

rhs[in] Right-hand side of the operation.

Returns:

This duration.

Duration operator%(const Duration &rhs) const noexcept

Performs the modulo operation.

Parameters:

rhs[in] Right-hand side of the operation.

Returns:

Result of the operation.

Duration operator%(uint64_t rhs) const noexcept

Performs the modulo operation.

Parameters:

rhs[in] Right-hand side of the operation.

Returns:

Result of the operation.

Duration &operator%=(const Duration &rhs) noexcept

Performs the modulo operation.

Parameters:

rhs[in] Right-hand side of the operation.

Returns:

This duration.

Duration &operator%=(uint64_t rhs) noexcept

Performs the modulo operation.

Parameters:

rhs[in] Right-hand side of the operation.

Returns:

This duration.

Comparison operators

bool operator==(const Duration &rhs) const noexcept

Compares two durations for equality.

Parameters:

rhs[in] Right-hand side of the comparison.

Returns:

True if the duration are equal, false otherwise.

bool operator!=(const Duration &rhs) const noexcept

Compares two durations for inequality.

Parameters:

rhs[in] Right-hand side of the comparison.

Returns:

True if the duration are not equal, false otherwise.

bool operator<(const Duration &rhs) const noexcept

Compares two durations.

Parameters:

rhs[in] Right-hand side of the comparison.

Returns:

True if this duration is shorter than rhs, false otherwise.

bool operator<=(const Duration &rhs) const noexcept

Compares two durations.

Parameters:

rhs[in] Right-hand side of the comparison.

Returns:

True if this duration is shorter than or equal to rhs, false otherwise.

bool operator>(const Duration &rhs) const noexcept

Compares two durations.

Parameters:

rhs[in] Right-hand side of the comparison.

Returns:

True if this duration is longer than rhs, false otherwise.

bool operator>=(const Duration &rhs) const noexcept

Compares two durations.

Parameters:

rhs[in] Right-hand side of the comparison.

Returns:

True if this duration is longer than or equal to rhs, false otherwise.

Public Functions

Duration() noexcept

Creates a new Duration instance with zero milliseconds.

explicit Duration(uint64_t milliseconds) noexcept

Creates a new Duration instance from the given number of milliseconds.

Parameters:

milliseconds[in] Number of milliseconds.

Duration(std::chrono::duration<uint64_t, std::milli> duration) noexcept

Creates a new Duration instance from an std::chrono::duration.

Parameters:

duration[in] Duration.

Duration(const Duration&) = default

Creates a copy of a Duration instance.

Duration &operator=(const Duration&) = default

Assigns the contents of one Duration to another.

Returns:

Result of the operation.

operator std::chrono::duration<uint64_t, std::milli>() const noexcept

Returns the stored duration as an std::chrono::duration.

Returns:

Duration as std::chrono::duration.

double toSec() const noexcept

Returns the stored duration in [s].

Returns:

Duration in [s].

uint64_t toMSec() const noexcept

Returns the stored duration in [ms].

Returns:

Duration in [ms].