C++ Utilities  4.11.0
Common C++ classes and routines used by my applications such as argument parser, IO and conversion utilities
Public Member Functions | Static Public Member Functions | Static Public Attributes | Friends | List of all members
ChronoUtilities::TimeSpan Class Reference

Represents a time interval. More...

#include <timespan.h>

Public Member Functions

constexpr TimeSpan ()
 Constructs a new instance of the TimeSpan class with zero ticks. More...
 
constexpr TimeSpan (int64 ticks)
 Constructs a new instance of the TimeSpan class with the specified number of ticks. More...
 
constexpr int64 totalTicks () const
 Gets the number of ticks that represent the value of the current TimeSpan class. More...
 
constexpr double totalMicroseconds () const
 Gets the value of the current TimeSpan class expressed in whole and fractional microseconds. More...
 
constexpr double totalMilliseconds () const
 Gets the value of the current TimeSpan class expressed in whole and fractional milliseconds. More...
 
constexpr double totalSeconds () const
 Gets the value of the current TimeSpan class expressed in whole and fractional seconds. More...
 
constexpr double totalMinutes () const
 Gets the value of the current TimeSpan class expressed in whole and fractional minutes. More...
 
constexpr double totalHours () const
 Gets the value of the current TimeSpan class expressed in whole and fractional hours. More...
 
constexpr double totalDays () const
 Gets the value of the current TimeSpan class expressed in whole and fractional days. More...
 
constexpr int nanoseconds () const
 Gets the nanoseconds component of the time interval represented by the current TimeSpan class. More...
 
constexpr int microseconds () const
 Gets the microseconds component of the time interval represented by the current TimeSpan class. More...
 
constexpr int milliseconds () const
 Gets the miliseconds component of the time interval represented by the current TimeSpan class. More...
 
constexpr int seconds () const
 Gets the seconds component of the time interval represented by the current TimeSpan class. More...
 
constexpr int minutes () const
 Gets the minutes component of the time interval represented by the current TimeSpan class. More...
 
constexpr int hours () const
 Gets the hours component of the time interval represented by the current TimeSpan class. More...
 
constexpr int days () const
 Gets the days component of the time interval represented by the current TimeSpan class. More...
 
constexpr bool operator== (const TimeSpan &other) const
 Indicates whether two TimeSpan instances are equal. More...
 
constexpr bool operator!= (const TimeSpan &other) const
 Indicates whether two TimeSpan instances are not equal. More...
 
constexpr bool operator< (const TimeSpan &other) const
 Indicates whether a specified TimeSpan is less than another specified TimeSpan. More...
 
constexpr bool operator> (const TimeSpan &other) const
 Indicates whether a specified TimeSpan is greater than another specified TimeSpan. More...
 
constexpr bool operator<= (const TimeSpan &other) const
 Indicates whether a specified TimeSpan is less or equal than another specified TimeSpan. More...
 
constexpr bool operator>= (const TimeSpan &other) const
 Indicates whether a specified TimeSpan is greater or equal than another specified TimeSpan. More...
 
constexpr TimeSpan operator+ (const TimeSpan &other) const
 Adds two TimeSpan instances. More...
 
constexpr TimeSpan operator- (const TimeSpan &other) const
 Substracts two TimeSpan instances. More...
 
TimeSpanoperator+= (const TimeSpan &other)
 Adds another TimeSpan to the current instance. More...
 
TimeSpanoperator-= (const TimeSpan &other)
 Substracts another TimeSpan from the current instance. More...
 
std::string toString (TimeSpanOutputFormat format=TimeSpanOutputFormat::Normal, bool fullSeconds=false) const
 Converts the value of the current TimeSpan object to its equivalent std::string representation according the given format. More...
 
void toString (std::string &result, TimeSpanOutputFormat format=TimeSpanOutputFormat::Normal, bool fullSeconds=false) const
 Converts the value of the current TimeSpan object to its equivalent std::string representation according the given format. More...
 
constexpr bool isNull () const
 Returns ture if the time interval represented by the current TimeSpan class is null. More...
 
constexpr bool isNegative () const
 Returns ture if the time interval represented by the current TimeSpan class is negative. More...
 
constexpr bool isNegativeInfinity () const
 Returns whether the time inverval represented by the current instance is the smallest representable TimeSpan. More...
 
constexpr bool isInfinity () const
 Returns whether the time inverval represented by the current instance is the longest representable TimeSpan. More...
 

Static Public Member Functions

static constexpr TimeSpan fromMilliseconds (double milliseconds)
 Constructs a new instance of the TimeSpan class with the specified number of miliseconds. More...
 
static constexpr TimeSpan fromSeconds (double seconds)
 Constructs a new instance of the TimeSpan class with the specified number of seconds. More...
 
static constexpr TimeSpan fromMinutes (double minutes)
 Constructs a new instance of the TimeSpan class with the specified number of minutes. More...
 
static constexpr TimeSpan fromHours (double hours)
 Constructs a new instance of the TimeSpan class with the specified number of hours. More...
 
static constexpr TimeSpan fromDays (double days)
 Constructs a new instance of the TimeSpan class with the specified number of days. More...
 
static TimeSpan fromString (const std::string &str, char separator=':')
 Parses the given std::string as TimeSpan. More...
 
static TimeSpan fromString (const char *str, char separator)
 Parses the given C-style string as TimeSpan. More...
 
static constexpr TimeSpan negativeInfinity ()
 Constructs a new instace of the TimeSpan class with the minimal number of ticks. More...
 
static constexpr TimeSpan infinity ()
 Constructs a new instace of the TimeSpan class with the maximal number of ticks. More...
 

Static Public Attributes

static constexpr int64 nanosecondsPerTick = 100uL
 
static constexpr int64 ticksPerMicrosecond = 10uL
 
static constexpr uint64 ticksPerMillisecond = 10000uL
 
static constexpr uint64 ticksPerSecond = 10000000uL
 
static constexpr uint64 ticksPerMinute = 600000000uL
 
static constexpr uint64 ticksPerHour = 36000000000uL
 
static constexpr uint64 ticksPerDay = 864000000000uL
 

Friends

class DateTime
 

Detailed Description

Represents a time interval.

Remarks
Time values are measured in 100-nanosecond units called ticks.

Definition at line 27 of file timespan.h.

Constructor & Destructor Documentation

◆ TimeSpan() [1/2]

constexpr ChronoUtilities::TimeSpan::TimeSpan ( )
inlineexplicit

Constructs a new instance of the TimeSpan class with zero ticks.

Definition at line 101 of file timespan.h.

◆ TimeSpan() [2/2]

constexpr ChronoUtilities::TimeSpan::TimeSpan ( int64  ticks)
inlineexplicit

Constructs a new instance of the TimeSpan class with the specified number of ticks.

Definition at line 109 of file timespan.h.

Member Function Documentation

◆ days()

constexpr int ChronoUtilities::TimeSpan::days ( ) const
inline

Gets the days component of the time interval represented by the current TimeSpan class.

Definition at line 287 of file timespan.h.

◆ fromDays()

constexpr TimeSpan ChronoUtilities::TimeSpan::fromDays ( double  days)
inlinestatic

Constructs a new instance of the TimeSpan class with the specified number of days.

Definition at line 149 of file timespan.h.

◆ fromHours()

constexpr TimeSpan ChronoUtilities::TimeSpan::fromHours ( double  hours)
inlinestatic

Constructs a new instance of the TimeSpan class with the specified number of hours.

Definition at line 141 of file timespan.h.

◆ fromMilliseconds()

constexpr TimeSpan ChronoUtilities::TimeSpan::fromMilliseconds ( double  milliseconds)
inlinestatic

Constructs a new instance of the TimeSpan class with the specified number of miliseconds.

Definition at line 117 of file timespan.h.

◆ fromMinutes()

constexpr TimeSpan ChronoUtilities::TimeSpan::fromMinutes ( double  minutes)
inlinestatic

Constructs a new instance of the TimeSpan class with the specified number of minutes.

Definition at line 133 of file timespan.h.

◆ fromSeconds()

constexpr TimeSpan ChronoUtilities::TimeSpan::fromSeconds ( double  seconds)
inlinestatic

Constructs a new instance of the TimeSpan class with the specified number of seconds.

Definition at line 125 of file timespan.h.

◆ fromString() [1/2]

TimeSpan ChronoUtilities::TimeSpan::fromString ( const std::string &  str,
char  separator = ':' 
)
inlinestatic

Parses the given std::string as TimeSpan.

Definition at line 157 of file timespan.h.

◆ fromString() [2/2]

TimeSpan TimeSpan::fromString ( const char *  str,
char  separator 
)
static

Parses the given C-style string as TimeSpan.

Definition at line 23 of file timespan.cpp.

◆ hours()

constexpr int ChronoUtilities::TimeSpan::hours ( ) const
inline

Gets the hours component of the time interval represented by the current TimeSpan class.

Definition at line 279 of file timespan.h.

◆ infinity()

constexpr TimeSpan ChronoUtilities::TimeSpan::infinity ( )
inlinestatic

Constructs a new instace of the TimeSpan class with the maximal number of ticks.

Definition at line 173 of file timespan.h.

◆ isInfinity()

constexpr bool ChronoUtilities::TimeSpan::isInfinity ( ) const
inline

Returns whether the time inverval represented by the current instance is the longest representable TimeSpan.

Definition at line 401 of file timespan.h.

◆ isNegative()

constexpr bool ChronoUtilities::TimeSpan::isNegative ( ) const
inline

Returns ture if the time interval represented by the current TimeSpan class is negative.

Definition at line 385 of file timespan.h.

◆ isNegativeInfinity()

constexpr bool ChronoUtilities::TimeSpan::isNegativeInfinity ( ) const
inline

Returns whether the time inverval represented by the current instance is the smallest representable TimeSpan.

Definition at line 393 of file timespan.h.

◆ isNull()

constexpr bool ChronoUtilities::TimeSpan::isNull ( ) const
inline

Returns ture if the time interval represented by the current TimeSpan class is null.

Definition at line 377 of file timespan.h.

◆ microseconds()

constexpr int ChronoUtilities::TimeSpan::microseconds ( ) const

Gets the microseconds component of the time interval represented by the current TimeSpan class.

Definition at line 247 of file timespan.h.

◆ milliseconds()

constexpr int ChronoUtilities::TimeSpan::milliseconds ( ) const
inline

Gets the miliseconds component of the time interval represented by the current TimeSpan class.

Definition at line 255 of file timespan.h.

◆ minutes()

constexpr int ChronoUtilities::TimeSpan::minutes ( ) const
inline

Gets the minutes component of the time interval represented by the current TimeSpan class.

Definition at line 271 of file timespan.h.

◆ nanoseconds()

constexpr int ChronoUtilities::TimeSpan::nanoseconds ( ) const

Gets the nanoseconds component of the time interval represented by the current TimeSpan class.

Remarks
The accuracy of the TimeSpan class is 100-nanoseconds. Hence the returned value will always have two zeros at the end (in decimal representation).

Definition at line 239 of file timespan.h.

◆ negativeInfinity()

constexpr TimeSpan ChronoUtilities::TimeSpan::negativeInfinity ( )
inlinestatic

Constructs a new instace of the TimeSpan class with the minimal number of ticks.

Definition at line 165 of file timespan.h.

◆ operator!=()

constexpr bool ChronoUtilities::TimeSpan::operator!= ( const TimeSpan other) const
inline

Indicates whether two TimeSpan instances are not equal.

Definition at line 303 of file timespan.h.

◆ operator+()

constexpr TimeSpan ChronoUtilities::TimeSpan::operator+ ( const TimeSpan other) const
inline

Adds two TimeSpan instances.

Definition at line 343 of file timespan.h.

◆ operator+=()

TimeSpan & ChronoUtilities::TimeSpan::operator+= ( const TimeSpan other)
inline

Adds another TimeSpan to the current instance.

Definition at line 359 of file timespan.h.

◆ operator-()

constexpr TimeSpan ChronoUtilities::TimeSpan::operator- ( const TimeSpan other) const
inline

Substracts two TimeSpan instances.

Definition at line 351 of file timespan.h.

◆ operator-=()

TimeSpan & ChronoUtilities::TimeSpan::operator-= ( const TimeSpan other)
inline

Substracts another TimeSpan from the current instance.

Definition at line 368 of file timespan.h.

◆ operator<()

constexpr bool ChronoUtilities::TimeSpan::operator< ( const TimeSpan other) const
inline

Indicates whether a specified TimeSpan is less than another specified TimeSpan.

Definition at line 311 of file timespan.h.

◆ operator<=()

constexpr bool ChronoUtilities::TimeSpan::operator<= ( const TimeSpan other) const
inline

Indicates whether a specified TimeSpan is less or equal than another specified TimeSpan.

Definition at line 327 of file timespan.h.

◆ operator==()

constexpr bool ChronoUtilities::TimeSpan::operator== ( const TimeSpan other) const
inline

Indicates whether two TimeSpan instances are equal.

Definition at line 295 of file timespan.h.

◆ operator>()

constexpr bool ChronoUtilities::TimeSpan::operator> ( const TimeSpan other) const
inline

Indicates whether a specified TimeSpan is greater than another specified TimeSpan.

Definition at line 319 of file timespan.h.

◆ operator>=()

constexpr bool ChronoUtilities::TimeSpan::operator>= ( const TimeSpan other) const
inline

Indicates whether a specified TimeSpan is greater or equal than another specified TimeSpan.

Definition at line 335 of file timespan.h.

◆ seconds()

constexpr int ChronoUtilities::TimeSpan::seconds ( ) const
inline

Gets the seconds component of the time interval represented by the current TimeSpan class.

Definition at line 263 of file timespan.h.

◆ toString() [1/2]

string TimeSpan::toString ( TimeSpanOutputFormat  format = TimeSpanOutputFormat::Normal,
bool  fullSeconds = false 
) const

Converts the value of the current TimeSpan object to its equivalent std::string representation according the given format.

If fullSeconds is true the time interval will be rounded to full seconds.

Definition at line 66 of file timespan.cpp.

◆ toString() [2/2]

void TimeSpan::toString ( std::string &  result,
TimeSpanOutputFormat  format = TimeSpanOutputFormat::Normal,
bool  fullSeconds = false 
) const

Converts the value of the current TimeSpan object to its equivalent std::string representation according the given format.

If fullSeconds is true the time interval will be rounded to full seconds.

The string representation will be stored in result.

Definition at line 81 of file timespan.cpp.

◆ totalDays()

constexpr double ChronoUtilities::TimeSpan::totalDays ( ) const
inline

Gets the value of the current TimeSpan class expressed in whole and fractional days.

Definition at line 229 of file timespan.h.

◆ totalHours()

constexpr double ChronoUtilities::TimeSpan::totalHours ( ) const
inline

Gets the value of the current TimeSpan class expressed in whole and fractional hours.

Definition at line 221 of file timespan.h.

◆ totalMicroseconds()

constexpr double ChronoUtilities::TimeSpan::totalMicroseconds ( ) const

Gets the value of the current TimeSpan class expressed in whole and fractional microseconds.

Definition at line 189 of file timespan.h.

◆ totalMilliseconds()

constexpr double ChronoUtilities::TimeSpan::totalMilliseconds ( ) const
inline

Gets the value of the current TimeSpan class expressed in whole and fractional milliseconds.

Definition at line 197 of file timespan.h.

◆ totalMinutes()

constexpr double ChronoUtilities::TimeSpan::totalMinutes ( ) const
inline

Gets the value of the current TimeSpan class expressed in whole and fractional minutes.

Definition at line 213 of file timespan.h.

◆ totalSeconds()

constexpr double ChronoUtilities::TimeSpan::totalSeconds ( ) const
inline

Gets the value of the current TimeSpan class expressed in whole and fractional seconds.

Definition at line 205 of file timespan.h.

◆ totalTicks()

constexpr int64 ChronoUtilities::TimeSpan::totalTicks ( ) const
inline

Gets the number of ticks that represent the value of the current TimeSpan class.

Definition at line 181 of file timespan.h.

Friends And Related Function Documentation

◆ DateTime

friend class DateTime
friend

Definition at line 28 of file timespan.h.

Member Data Documentation

◆ nanosecondsPerTick

constexpr int64 ChronoUtilities::TimeSpan::nanosecondsPerTick = 100uL
static

Definition at line 79 of file timespan.h.

◆ ticksPerDay

constexpr uint64 ChronoUtilities::TimeSpan::ticksPerDay = 864000000000uL
static

Definition at line 85 of file timespan.h.

◆ ticksPerHour

constexpr uint64 ChronoUtilities::TimeSpan::ticksPerHour = 36000000000uL
static

Definition at line 84 of file timespan.h.

◆ ticksPerMicrosecond

constexpr int64 ChronoUtilities::TimeSpan::ticksPerMicrosecond = 10uL
static

Definition at line 80 of file timespan.h.

◆ ticksPerMillisecond

constexpr uint64 ChronoUtilities::TimeSpan::ticksPerMillisecond = 10000uL
static

Definition at line 81 of file timespan.h.

◆ ticksPerMinute

constexpr uint64 ChronoUtilities::TimeSpan::ticksPerMinute = 600000000uL
static

Definition at line 83 of file timespan.h.

◆ ticksPerSecond

constexpr uint64 ChronoUtilities::TimeSpan::ticksPerSecond = 10000000uL
static

Definition at line 82 of file timespan.h.


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