Class Duration

Class Documentation

class Duration

Wraps the standard C++ duration to provide arithmetic, interactions with TimePoints and parsing/formatting functions.

Public Types

typedef SystemDuration Basis

Public Functions

inline Duration()
Duration(const std::string &str)
Duration(double seconds)
TimePoint operator+(const TimePoint &t) const

Add a Duration to a TimePoint to get a TimePoint (now + 7 days = next week).

TimePoint operator-(const TimePoint &t) const

Subtract a Duration from a TimePoint to get a TimePoint.

inline Duration &operator+=(const Duration &a)

Add-assign a Duration to this.

inline Duration &operator-=(const Duration &a)

Subtract-assign a Duration from this.

inline Duration &operator*=(double a)

Multiply-assign this Duration by a factor.

inline Duration &operator/=(double a)

Divide-assign this Duration by a factor.

inline Duration operator+(const Duration &a) const

Add two Durations.

inline Duration operator-(const Duration &a) const

Subtract one Duration from another.

inline double seconds() const

Return the length of this Duration in seconds.

std::istream &parse(std::istream &is)

Set this Duration by parsing the characters in an istream. The characters should either be an integer, representing a number of seconds, or an ISO 8601 P format duration (see https://en.wikipedia.org/wiki/ISO_8601#Durations for example).

inline Duration &parse(const std::string &str)

Set this Duration by parsing a string. The characters should either be an integer, representing a number of seconds, or an ISO 8601 P format duration (see https://en.wikipedia.org/wiki/ISO_8601#Durations for example).

inline std::ostream &format(std::ostream &os) const

Print the number of seconds represented by this Duration as a formatted value to an ostream.

inline std::string format() const

Return the string representation of the number of seconds represented by this Duration.

Public Members

friend TimePoint

Friends

friend Duration durationFromISO(const std::string&, int)