Duration Class Reference

Represents a duration. More...

#include <ArmarXCore/core/time/Duration.h>

Public Member Functions

 Duration ()
 Constructs a zero-duration. More...
 
bool isPositive () const
 Tests whether the duration is positive (value in µs > 0). More...
 
bool isZero () const
 
bool operator!= (const Duration &rhs) const
 
Duration operator* (double rhs) const
 
Duration operator* (int rhs) const
 
Duration operator* (std::int64_t rhs) const
 
Durationoperator*= (double rhs)
 
Durationoperator*= (int rhs)
 
Durationoperator*= (std::int64_t rhs)
 
Duration operator+ (const Duration &rhs) const
 
Durationoperator+= (const Duration &rhs)
 
Duration operator- () const
 
Duration operator- (const Duration &rhs) const
 
Durationoperator-= (const Duration &rhs)
 
double operator/ (const Duration &rhs) const
 
Duration operator/ (double rhs) const
 
Duration operator/ (int rhs) const
 
Duration operator/ (std::int64_t rhs) const
 
Durationoperator/= (double rhs)
 
Durationoperator/= (int rhs)
 
Durationoperator/= (std::int64_t rhs)
 
bool operator< (const Duration &rhs) const
 
bool operator<= (const Duration &rhs) const
 
bool operator== (const Duration &rhs) const
 
bool operator> (const Duration &rhs) const
 
bool operator>= (const Duration &rhs) const
 
std::int64_t toDays () const
 Returns the amount of days. More...
 
double toDaysDouble () const
 Returns the amount of days. More...
 
std::string toDurationString () const
 String representation of the current duration in minimal/default format. More...
 
std::string toDurationString (const std::string &format) const
 String representation of the current duration according to given format string. More...
 
std::int64_t toHours () const
 Returns the amount of hours. More...
 
double toHoursDouble () const
 Returns the amount of hours. More...
 
std::int64_t toMicroSeconds () const
 Returns the amount of microseconds. More...
 
double toMicroSecondsDouble () const
 Returns the amount of microseconds. More...
 
std::int64_t toMilliSeconds () const
 Returns the amount of milliseconds. More...
 
double toMilliSecondsDouble () const
 Returns the amount of milliseconds. More...
 
std::int64_t toMinutes () const
 Returns the amount of minutes. More...
 
double toMinutesDouble () const
 Returns the amount of minutes. More...
 
std::int64_t toSeconds () const
 Returns the amount of seconds. More...
 
double toSecondsDouble () const
 Returns the amount of seconds. More...
 

Static Public Member Functions

static Duration Days (std::int64_t days)
 Constructs a duration in days. More...
 
static Duration DaysDouble (double days)
 Constructs a duration in days. More...
 
static Duration Hours (std::int64_t hours)
 Constructs a duration in hours. More...
 
static Duration HoursDouble (double hours)
 Constructs a duration in hours. More...
 
static Duration MicroSeconds (std::int64_t microSeconds)
 Constructs a duration in microseconds. More...
 
static Duration MicroSecondsDouble (double microSeconds)
 Constructs a duration in microseconds. More...
 
static Duration MilliSeconds (std::int64_t milliSeconds)
 Constructs a duration in milliseconds. More...
 
static Duration MilliSecondsDouble (double milliSeconds)
 Constructs a duration in milliseconds. More...
 
static Duration Minutes (std::int64_t minutes)
 Constructs a duration in minutes. More...
 
static Duration MinutesDouble (double minutes)
 Constructs a duration in minutes. More...
 
static Duration Seconds (std::int64_t seconds)
 Constructs a duration in seconds. More...
 
static Duration SecondsDouble (double seconds)
 Constructs a duration in seconds. More...
 

Protected Member Functions

 Duration (std::int64_t microSeconds)
 

Protected Attributes

std::int64_t _microSeconds
 Current duration in microseconds. More...
 

Detailed Description

Represents a duration.

API and implementation to match IceUtil::Time (where applicable).

Definition at line 17 of file Duration.h.

Constructor & Destructor Documentation

◆ Duration() [1/2]

Duration ( )

Constructs a zero-duration.

Definition at line 14 of file Duration.cpp.

+ Here is the caller graph for this function:

◆ Duration() [2/2]

Duration ( std::int64_t  microSeconds)
protected

Definition at line 20 of file Duration.cpp.

Member Function Documentation

◆ Days()

Duration Days ( std::int64_t  days)
static

Constructs a duration in days.

Parameters
daysAmount of days.
Returns
Duration instance.

Definition at line 167 of file Duration.cpp.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ DaysDouble()

Duration DaysDouble ( double  days)
static

Constructs a duration in days.

Parameters
daysAmount of days.
Returns
Duration instance.

Definition at line 174 of file Duration.cpp.

+ Here is the call graph for this function:

◆ Hours()

Duration Hours ( std::int64_t  hours)
static

Constructs a duration in hours.

Parameters
hoursAmount of hours.
Returns
Duration instance.

Definition at line 139 of file Duration.cpp.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ HoursDouble()

Duration HoursDouble ( double  hours)
static

Constructs a duration in hours.

Parameters
hoursAmount of hours.
Returns
Duration instance.

Definition at line 146 of file Duration.cpp.

+ Here is the call graph for this function:

◆ isPositive()

bool isPositive ( ) const

Tests whether the duration is positive (value in µs > 0).

Returns
True if duration is positive, else otherwise.

Definition at line 195 of file Duration.cpp.

+ Here is the caller graph for this function:

◆ isZero()

bool isZero ( ) const

Definition at line 202 of file Duration.cpp.

+ Here is the caller graph for this function:

◆ MicroSeconds()

Duration MicroSeconds ( std::int64_t  microSeconds)
static

Constructs a duration in microseconds.

Parameters
microSecondsAmount of microseconds.
Returns
Duration instance.

Definition at line 27 of file Duration.cpp.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ MicroSecondsDouble()

Duration MicroSecondsDouble ( double  microSeconds)
static

Constructs a duration in microseconds.

Parameters
microSecondsAmount of microseconds.
Returns
Duration instance.

Definition at line 34 of file Duration.cpp.

+ Here is the call graph for this function:

◆ MilliSeconds()

Duration MilliSeconds ( std::int64_t  milliSeconds)
static

Constructs a duration in milliseconds.

Parameters
milliSecondsAmount of milliseconds.
Returns
Duration instance.

Definition at line 55 of file Duration.cpp.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ MilliSecondsDouble()

Duration MilliSecondsDouble ( double  milliSeconds)
static

Constructs a duration in milliseconds.

Parameters
milliSecondsAmount of milliseconds.
Returns
Duration instance.

Definition at line 62 of file Duration.cpp.

◆ Minutes()

Duration Minutes ( std::int64_t  minutes)
static

Constructs a duration in minutes.

Parameters
minutesAmount of minutes.
Returns
Duration instance.

Definition at line 111 of file Duration.cpp.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ MinutesDouble()

Duration MinutesDouble ( double  minutes)
static

Constructs a duration in minutes.

Parameters
minutesAmount of minutes.
Returns
Duration instance.

Definition at line 118 of file Duration.cpp.

+ Here is the call graph for this function:

◆ operator!=()

bool operator!= ( const Duration rhs) const

Definition at line 430 of file Duration.cpp.

◆ operator*() [1/3]

Duration operator* ( double  rhs) const

Definition at line 312 of file Duration.cpp.

◆ operator*() [2/3]

Duration operator* ( int  rhs) const

Definition at line 321 of file Duration.cpp.

◆ operator*() [3/3]

Duration operator* ( std::int64_t  rhs) const

Definition at line 328 of file Duration.cpp.

◆ operator*=() [1/3]

Duration & operator*= ( double  rhs)

Definition at line 335 of file Duration.cpp.

◆ operator*=() [2/3]

Duration & operator*= ( int  rhs)

Definition at line 343 of file Duration.cpp.

◆ operator*=() [3/3]

Duration & operator*= ( std::int64_t  rhs)

Definition at line 350 of file Duration.cpp.

◆ operator+()

Duration operator+ ( const Duration rhs) const

Definition at line 275 of file Duration.cpp.

◆ operator+=()

Duration & operator+= ( const Duration rhs)

Definition at line 282 of file Duration.cpp.

◆ operator-() [1/2]

Duration operator- ( ) const

Definition at line 290 of file Duration.cpp.

◆ operator-() [2/2]

Duration operator- ( const Duration rhs) const

Definition at line 297 of file Duration.cpp.

◆ operator-=()

Duration & operator-= ( const Duration rhs)

Definition at line 304 of file Duration.cpp.

◆ operator/() [1/4]

double operator/ ( const Duration rhs) const

Definition at line 357 of file Duration.cpp.

◆ operator/() [2/4]

Duration operator/ ( double  rhs) const

Definition at line 364 of file Duration.cpp.

◆ operator/() [3/4]

Duration operator/ ( int  rhs) const

Definition at line 373 of file Duration.cpp.

◆ operator/() [4/4]

Duration operator/ ( std::int64_t  rhs) const

Definition at line 380 of file Duration.cpp.

◆ operator/=() [1/3]

Duration & operator/= ( double  rhs)

Definition at line 387 of file Duration.cpp.

◆ operator/=() [2/3]

Duration & operator/= ( int  rhs)

Definition at line 395 of file Duration.cpp.

◆ operator/=() [3/3]

Duration & operator/= ( std::int64_t  rhs)

Definition at line 402 of file Duration.cpp.

◆ operator<()

bool operator< ( const Duration rhs) const

Definition at line 409 of file Duration.cpp.

◆ operator<=()

bool operator<= ( const Duration rhs) const

Definition at line 416 of file Duration.cpp.

◆ operator==()

bool operator== ( const Duration rhs) const

Definition at line 423 of file Duration.cpp.

◆ operator>()

bool operator> ( const Duration rhs) const

Definition at line 444 of file Duration.cpp.

◆ operator>=()

bool operator>= ( const Duration rhs) const

Definition at line 437 of file Duration.cpp.

◆ Seconds()

Duration Seconds ( std::int64_t  seconds)
static

Constructs a duration in seconds.

Parameters
secondsAmount of seconds.
Returns
Duration instance.

Definition at line 83 of file Duration.cpp.

+ Here is the caller graph for this function:

◆ SecondsDouble()

Duration SecondsDouble ( double  seconds)
static

Constructs a duration in seconds.

Parameters
secondsAmount of seconds.
Returns
Duration instance.

Definition at line 90 of file Duration.cpp.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ toDays()

std::int64_t toDays ( ) const

Returns the amount of days.

Returns
Amount of days.

Definition at line 181 of file Duration.cpp.

+ Here is the call graph for this function:

◆ toDaysDouble()

double toDaysDouble ( ) const

Returns the amount of days.

Returns
Amount of days.

Definition at line 188 of file Duration.cpp.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ toDurationString() [1/2]

std::string toDurationString ( ) const

String representation of the current duration in minimal/default format.

The minimal representation is a float representation with max. 3 decimals. The unit will be determined by the highest unit whose value is non-zero. For example, 3 seconds and 500 milliseconds => "3.5s".

Returns
Formatted duration.

Definition at line 209 of file Duration.cpp.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ toDurationString() [2/2]

std::string toDurationString ( const std::string &  format) const

String representation of the current duration according to given format string.

The format is according to https://en.cppreference.com/w/cpp/chrono/c/strftime. For milli seconds and micro seconds, special specifiers "%%msec" and "%%usec" were added respectively.

Example format string for "10m 10.987s": "%Mm %S.%%msecs".

Parameters
formatFormat string.
Returns
Formatted duration.

Definition at line 251 of file Duration.cpp.

◆ toHours()

std::int64_t toHours ( ) const

Returns the amount of hours.

Returns
Amount of hours.

Definition at line 153 of file Duration.cpp.

+ Here is the call graph for this function:

◆ toHoursDouble()

double toHoursDouble ( ) const

Returns the amount of hours.

Returns
Amount of hours.

Definition at line 160 of file Duration.cpp.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ toMicroSeconds()

std::int64_t toMicroSeconds ( ) const

Returns the amount of microseconds.

Returns
Amount of microseconds.

Definition at line 41 of file Duration.cpp.

+ Here is the caller graph for this function:

◆ toMicroSecondsDouble()

double toMicroSecondsDouble ( ) const

Returns the amount of microseconds.

Returns
Amount of microseconds.

Definition at line 48 of file Duration.cpp.

+ Here is the caller graph for this function:

◆ toMilliSeconds()

std::int64_t toMilliSeconds ( ) const

Returns the amount of milliseconds.

Returns
Amount of milliseconds.

Definition at line 69 of file Duration.cpp.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ toMilliSecondsDouble()

double toMilliSecondsDouble ( ) const

Returns the amount of milliseconds.

Returns
Amount of milliseconds.

Definition at line 76 of file Duration.cpp.

+ Here is the caller graph for this function:

◆ toMinutes()

std::int64_t toMinutes ( ) const

Returns the amount of minutes.

Returns
Amount of minutes.

Definition at line 125 of file Duration.cpp.

+ Here is the call graph for this function:

◆ toMinutesDouble()

double toMinutesDouble ( ) const

Returns the amount of minutes.

Returns
Amount of minutes.

Definition at line 132 of file Duration.cpp.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ toSeconds()

std::int64_t toSeconds ( ) const

Returns the amount of seconds.

Returns
Amount of seconds.

Definition at line 97 of file Duration.cpp.

+ Here is the caller graph for this function:

◆ toSecondsDouble()

double toSecondsDouble ( ) const

Returns the amount of seconds.

Returns
Amount of seconds.

Definition at line 104 of file Duration.cpp.

+ Here is the caller graph for this function:

Member Data Documentation

◆ _microSeconds

std::int64_t _microSeconds
protected

Current duration in microseconds.

Definition at line 271 of file Duration.h.


The documentation for this class was generated from the following files: