C++ Utilities
5.8.0
Useful C++ classes and routines such as argument parser, IO and conversion utilities
|
Go to the documentation of this file. 1 #ifndef CHRONO_UTILITIES_TIMESPAN_H
2 #define CHRONO_UTILITIES_TIMESPAN_H
30 explicit constexpr
TimeSpan(std::int64_t ticks);
32 static constexpr
TimeSpan fromMilliseconds(
double milliseconds);
33 static constexpr
TimeSpan fromSeconds(
double seconds);
34 static constexpr
TimeSpan fromMinutes(
double minutes);
35 static constexpr
TimeSpan fromHours(
double hours);
36 static constexpr
TimeSpan fromDays(
double days);
37 static TimeSpan fromString(
const std::string &str,
char separator =
':');
38 static TimeSpan fromString(
const char *str,
char separator);
39 static constexpr
TimeSpan negativeInfinity();
40 static constexpr
TimeSpan infinity();
42 std::int64_t &ticks();
43 constexpr std::int64_t totalTicks()
const;
44 constexpr
double totalMicroseconds()
const;
45 constexpr
double totalMilliseconds()
const;
46 constexpr
double totalSeconds()
const;
47 constexpr
double totalMinutes()
const;
48 constexpr
double totalHours()
const;
49 constexpr
double totalDays()
const;
51 constexpr
int nanoseconds()
const;
52 constexpr
int microseconds()
const;
53 constexpr
int milliseconds()
const;
54 constexpr
int seconds()
const;
55 constexpr
int minutes()
const;
56 constexpr
int hours()
const;
57 constexpr
int days()
const;
60 constexpr
bool operator!=(
const TimeSpan &other)
const;
61 constexpr
bool operator<(
const TimeSpan &other)
const;
62 constexpr
bool operator>(
const TimeSpan &other)
const;
63 constexpr
bool operator<=(
const TimeSpan &other)
const;
64 constexpr
bool operator>=(
const TimeSpan &other)
const;
67 constexpr
TimeSpan operator*(
double factor)
const;
68 constexpr
TimeSpan operator/(
double factor)
const;
69 constexpr
double operator/(
TimeSpan other)
const;
75 std::string toString(
TimeSpanOutputFormat format = TimeSpanOutputFormat::Normal,
bool fullSeconds =
false)
const;
76 void toString(std::string &result,
TimeSpanOutputFormat format = TimeSpanOutputFormat::Normal,
bool fullSeconds =
false)
const;
77 constexpr
bool isNull()
const;
78 constexpr
bool isNegative()
const;
79 constexpr
bool isNegativeInfinity()
const;
80 constexpr
bool isInfinity()
const;
82 static constexpr std::int64_t nanosecondsPerTick = 100uL;
83 static constexpr std::int64_t ticksPerMicrosecond = 10uL;
84 static constexpr std::int64_t ticksPerMillisecond = 10000uL;
85 static constexpr std::int64_t ticksPerSecond = 10000000uL;
86 static constexpr std::int64_t ticksPerMinute = 600000000uL;
87 static constexpr std::int64_t ticksPerHour = 36000000000uL;
88 static constexpr std::int64_t ticksPerDay = 864000000000uL;
168 return TimeSpan(std::numeric_limits<decltype(m_ticks)>::
min());
176 return TimeSpan(std::numeric_limits<decltype(m_ticks)>::
max());
216 return static_cast<double>(m_ticks) /
static_cast<double>(
ticksPerSecond);
224 return static_cast<double>(m_ticks) /
static_cast<double>(
ticksPerMinute);
232 return static_cast<double>(m_ticks) /
static_cast<double>(
ticksPerHour);
240 return static_cast<double>(m_ticks) /
static_cast<double>(
ticksPerDay);
306 return m_ticks == other.m_ticks;
314 return m_ticks != other.m_ticks;
322 return m_ticks < other.m_ticks;
330 return m_ticks > other.m_ticks;
338 return m_ticks <= other.m_ticks;
346 return m_ticks >= other.m_ticks;
354 return TimeSpan(m_ticks + other.m_ticks);
362 return TimeSpan(m_ticks - other.m_ticks);
386 return static_cast<double>(m_ticks) /
static_cast<double>(other.m_ticks);
394 m_ticks += other.m_ticks;
403 m_ticks -= other.m_ticks;
412 m_ticks = m_ticks * factor;
421 m_ticks = m_ticks / factor;
434 toString(result, format, fullSeconds);
459 return m_ticks == std::numeric_limits<decltype(m_ticks)>
::min();
467 return m_ticks == std::numeric_limits<decltype(m_ticks)>
::max();
481 #endif // CHRONO_UTILITIES_TIMESPAN_H
constexpr bool operator!=(const TimeSpan &other) const
Indicates whether two TimeSpan instances are not equal.
static constexpr std::int64_t ticksPerDay
constexpr double totalMilliseconds() const
Returns the value of the current TimeSpan class expressed in whole and fractional milliseconds.
static constexpr std::int64_t ticksPerMillisecond
constexpr bool operator<(const TimeSpan &other) const
Indicates whether a specified TimeSpan is less than another specified TimeSpan.
static constexpr TimeSpan fromMilliseconds(double milliseconds)
Constructs a new instance of the TimeSpan class with the specified number of miliseconds.
constexpr double totalMicroseconds() const
Returns the value of the current TimeSpan class expressed in whole and fractional microseconds.
TimeSpan & operator-=(const TimeSpan &other)
Substracts another TimeSpan from the current instance.
static constexpr TimeSpan negativeInfinity()
Constructs a new instace of the TimeSpan class with the minimal number of ticks.
CPP_UTILITIES_EXPORT DateTime operator+(DateTime begin, Period period)
Adds the specified period to the specified date.
constexpr TimeSpan()
Constructs a new instance of the TimeSpan class with zero ticks.
constexpr int milliseconds() const
Returns the miliseconds component of the time interval represented by the current TimeSpan class.
constexpr bool isNegativeInfinity() const
Returns whether the time inverval represented by the current instance is the smallest representable T...
constexpr int seconds() const
Returns the seconds component of the time interval represented by the current TimeSpan class.
static constexpr std::int64_t ticksPerMicrosecond
constexpr TimeSpan operator/(double factor) const
Divides a TimeSpan by the specified factor.
TimeSpan & operator/=(double factor)
Divides the current instance by the specified factor.
std::int64_t & ticks()
Returns a mutable reference to the total ticks.
constexpr TimeSpan operator*(double factor) const
Multiplies a TimeSpan by the specified factor.
static TimeSpan fromString(const std::string &str, char separator=':')
Parses the given std::string as TimeSpan.
constexpr T max(T first, T second)
Returns the greatest of the given items.
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 accord...
constexpr bool operator>(const TimeSpan &other) const
Indicates whether a specified TimeSpan is greater than another specified TimeSpan.
constexpr double totalDays() const
Returns the value of the current TimeSpan class expressed in whole and fractional days.
constexpr bool operator>=(const TimeSpan &other) const
Indicates whether a specified TimeSpan is greater or equal than another specified TimeSpan.
constexpr std::int64_t totalTicks() const
Returns the number of ticks that represent the value of the current TimeSpan class.
size_t operator()(const CppUtilities::TimeSpan &timeSpan) const
TimeSpanOutputFormat
Specifies the output format.
constexpr TimeSpan operator-(const TimeSpan &other) const
Substracts one TimeSpan instance from another.
constexpr int hours() const
Returns the hours component of the time interval represented by the current TimeSpan class.
constexpr int minutes() const
Returns the minutes component of the time interval represented by the current TimeSpan class.
Contains all utilities provides by the c++utilities library.
static constexpr std::int64_t ticksPerHour
static constexpr TimeSpan fromMinutes(double minutes)
Constructs a new instance of the TimeSpan class with the specified number of minutes.
constexpr int microseconds() const
Returns the microseconds component of the time interval represented by the current TimeSpan class.
constexpr FlagEnumClass & operator+=(FlagEnumClass &lhs, FlagEnumClass rhs)
static constexpr TimeSpan fromHours(double hours)
Constructs a new instance of the TimeSpan class with the specified number of hours.
constexpr FlagEnumClass & operator-=(FlagEnumClass &lhs, FlagEnumClass rhs)
TimeSpan & operator+=(const TimeSpan &other)
Adds another TimeSpan to the current instance.
constexpr T min(T first, T second)
Returns the smallest of the given items.
Represents a time interval.
constexpr double totalHours() const
Returns the value of the current TimeSpan class expressed in whole and fractional hours.
static constexpr std::int64_t nanosecondsPerTick
TimeSpan & operator*=(double factor)
Multiplies the current instance by the specified factor.
constexpr bool isNegative() const
Returns ture if the time interval represented by the current TimeSpan class is negative.
constexpr bool operator==(const TimeSpan &other) const
Indicates whether two TimeSpan instances are equal.
Represents an instant in time, typically expressed as a date and time of day.
static constexpr std::int64_t ticksPerSecond
constexpr bool isInfinity() const
Returns whether the time inverval represented by the current instance is the longest representable Ti...
#define CPP_UTILITIES_EXPORT
Marks the symbol to be exported by the c++utilities library.
static constexpr TimeSpan infinity()
Constructs a new instace of the TimeSpan class with the maximal number of ticks.
constexpr double totalMinutes() const
Returns the value of the current TimeSpan class expressed in whole and fractional minutes.
bool operator==(const AsHexNumber< T > &lhs, const AsHexNumber< T > &rhs)
Provides operator == required by CPPUNIT_ASSERT_EQUAL.
static constexpr std::int64_t ticksPerMinute
constexpr int nanoseconds() const
Returns the nanoseconds component of the time interval represented by the current TimeSpan class.
constexpr TimeSpan operator+(const TimeSpan &other) const
Adds two TimeSpan instances.
static constexpr TimeSpan fromSeconds(double seconds)
Constructs a new instance of the TimeSpan class with the specified number of seconds.
constexpr bool operator<=(const TimeSpan &other) const
Indicates whether a specified TimeSpan is less or equal than another specified TimeSpan.
constexpr bool isNull() const
Returns ture if the time interval represented by the current TimeSpan class is null.
static constexpr TimeSpan fromDays(double days)
Constructs a new instance of the TimeSpan class with the specified number of days.
constexpr int days() const
Returns the days component of the time interval represented by the current TimeSpan class.
constexpr double totalSeconds() const
Returns the value of the current TimeSpan class expressed in whole and fractional seconds.