1 #ifndef CHRONO_UTILITIES_TIMESPAN_H 2 #define CHRONO_UTILITIES_TIMESPAN_H 4 #include "../conversion/types.h" 34 static constexpr
TimeSpan fromMilliseconds(
double milliseconds);
35 static constexpr
TimeSpan fromSeconds(
double seconds);
36 static constexpr
TimeSpan fromMinutes(
double minutes);
37 static constexpr
TimeSpan fromHours(
double hours);
38 static constexpr
TimeSpan fromDays(
double days);
39 static TimeSpan fromString(
const std::string &str,
char separator =
':');
40 static TimeSpan fromString(
const char *str,
char separator);
41 static constexpr
TimeSpan negativeInfinity();
42 static constexpr
TimeSpan infinity();
44 constexpr
int64 totalTicks()
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 milliseconds()
const;
52 constexpr
int seconds()
const;
53 constexpr
int minutes()
const;
54 constexpr
int hours()
const;
55 constexpr
int days()
const;
58 constexpr
bool operator!=(
const TimeSpan &other)
const;
59 constexpr
bool operator<(
const TimeSpan &other)
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;
70 constexpr
bool isNull()
const;
71 constexpr
bool isNegative()
const;
72 constexpr
bool isNegativeInfinity()
const;
73 constexpr
bool isInfinity()
const;
76 static constexpr
uint64 ticksPerMillisecond = 10000uL;
77 static constexpr
uint64 ticksPerSecond = 10000000uL;
78 static constexpr
uint64 ticksPerMinute = 600000000uL;
79 static constexpr
uint64 ticksPerHour = 36000000000uL;
80 static constexpr
uint64 ticksPerDay = 864000000000uL;
83 static constexpr
int64 m_ticksPerMillisecond = 10000L;
84 static constexpr
int64 m_ticksPerSecond = 10000000L;
85 static constexpr
int64 m_ticksPerMinute = 600000000L;
86 static constexpr
int64 m_ticksPerHour = 36000000000L;
87 static constexpr
int64 m_ticksPerDay = 864000000000L;
114 return TimeSpan(static_cast<int64>(milliseconds * static_cast<double>(m_ticksPerMillisecond)));
122 return TimeSpan(static_cast<int64>(seconds * static_cast<double>(m_ticksPerSecond)));
130 return TimeSpan(static_cast<int64>(minutes * static_cast<double>(m_ticksPerMinute)));
138 return TimeSpan(static_cast<int64>(hours * static_cast<double>(m_ticksPerHour)));
146 return TimeSpan(static_cast<int64>(days * static_cast<double>(m_ticksPerDay)));
162 return TimeSpan(std::numeric_limits<decltype(m_ticks)>::min());
170 return TimeSpan(std::numeric_limits<decltype(m_ticks)>::max());
186 return static_cast<double>(m_ticks) / static_cast<double>(m_ticksPerMillisecond);
194 return static_cast<double>(m_ticks) / static_cast<double>(m_ticksPerSecond);
202 return static_cast<double>(m_ticks) / static_cast<double>(m_ticksPerMinute);
210 return static_cast<double>(m_ticks) / static_cast<double>(m_ticksPerHour);
218 return static_cast<double>(m_ticks) / static_cast<double>(m_ticksPerDay);
226 return (m_ticks / m_ticksPerMillisecond) % 1000l;
234 return (m_ticks / m_ticksPerSecond) % 60l;
242 return (m_ticks / m_ticksPerMinute) % 60l;
250 return (m_ticks / m_ticksPerHour) % 24l;
258 return (m_ticks / m_ticksPerDay);
266 return m_ticks == other.m_ticks;
274 return m_ticks != other.m_ticks;
282 return m_ticks < other.m_ticks;
290 return m_ticks > other.m_ticks;
298 return m_ticks <= other.m_ticks;
306 return m_ticks >= other.m_ticks;
314 return TimeSpan(m_ticks + other.m_ticks);
322 return TimeSpan(m_ticks - other.m_ticks);
330 m_ticks += other.m_ticks;
339 m_ticks -= other.m_ticks;
364 return m_ticks == std::numeric_limits<decltype(m_ticks)>::min();
372 return m_ticks == std::numeric_limits<decltype(m_ticks)>::max();
385 #endif // CHRONO_UTILITIES_TIMESPAN_H TimeSpanOutputFormat
Specifies the output format.
constexpr double totalMilliseconds() const
Gets the value of the current TimeSpan class expressed in whole and fractional milliseconds.
static constexpr TimeSpan fromHours(double hours)
Constructs a new instance of the TimeSpan class with the specified number of hours.
static constexpr TimeSpan negativeInfinity()
Constructs a new instace of the TimeSpan class with the minimal number of ticks.
size_t operator()(const ChronoUtilities::TimeSpan &timeSpan) const
std::int64_t int64
signed 64-bit integer
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 a specified TimeSpan is less or equal than another specified TimeSpan.
Represents an instant in time, typically expressed as a date and time of day.
Contains classes providing a means for handling date and time information.
constexpr int64 totalTicks() const
Gets the number of ticks that represent the value of the current TimeSpan class.
constexpr int days() const
Gets the days component of the time interval represented by the current TimeSpan class.
constexpr double totalMinutes() const
Gets the value of the current TimeSpan class expressed in whole and fractional minutes.
Represents a time interval.
constexpr int hours() const
Gets the hours component of the time interval represented by the current TimeSpan class...
static constexpr TimeSpan fromMilliseconds(double milliseconds)
Constructs a new instance of the TimeSpan class with the specified number of miliseconds.
constexpr TimeSpan()
Constructs a new instance of the TimeSpan class with zero ticks.
static constexpr TimeSpan fromSeconds(double seconds)
Constructs a new instance of the TimeSpan class with the specified number of seconds.
std::uint64_t uint64
unsigned 64-bit integer
TimeSpan & operator-=(const TimeSpan &other)
Substracts another TimeSpan from the current instance.
constexpr double totalHours() const
Gets the value of the current TimeSpan class expressed in whole and fractional hours.
constexpr bool isNull() const
Returns ture if the time interval represented by the current TimeSpan class is null.
constexpr bool operator>=(const TimeSpan &other) const
Indicates whether a specified TimeSpan is greater or equal than another specified TimeSpan...
constexpr bool operator<(const TimeSpan &other) const
Indicates whether a specified TimeSpan is less than another specified TimeSpan.
constexpr int minutes() const
Gets the minutes component of the time interval represented by the current TimeSpan class...
bool operator==(const AsHexNumber< T > &lhs, const AsHexNumber< T > &rhs)
Provides operator == required by CPPUNIT_ASSERT_EQUAL.
constexpr TimeSpan operator-(const TimeSpan &other) const
Substracts two TimeSpan instances.
constexpr int milliseconds() const
Gets the miliseconds component of the time interval represented by the current TimeSpan class...
static constexpr TimeSpan fromDays(double days)
Constructs a new instance of the TimeSpan class with the specified number of days.
constexpr bool isInfinity() const
Returns whether the time inverval represented by the current instance is the longest representable Ti...
constexpr double totalSeconds() const
Gets the value of the current TimeSpan class expressed in whole and fractional seconds.
constexpr bool operator!=(const TimeSpan &other) const
Indicates whether two TimeSpan instances are not equal.
TimeSpan & operator+=(const TimeSpan &other)
Adds another TimeSpan to the current instance.
constexpr int seconds() const
Gets the seconds component of the time interval represented by the current TimeSpan class...
constexpr bool operator==(const TimeSpan &other) const
Indicates whether two TimeSpan instances are equal.
std::string operator+(const Tuple &lhs, const std::string &rhs)
Allows construction of final string from previously constructed string-tuple and trailing string via ...
constexpr double totalDays() const
Gets 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 than another specified TimeSpan.
constexpr bool isNegativeInfinity() const
Returns whether the time inverval represented by the current instance is the smallest representable T...
constexpr TimeSpan operator+(const TimeSpan &other) const
Adds two TimeSpan instances.
static constexpr TimeSpan infinity()
Constructs a new instace of the TimeSpan class with the maximal number of ticks.
static TimeSpan fromString(const std::string &str, char separator=':')
Parses the given std::string as TimeSpan.
#define CPP_UTILITIES_EXPORT
Marks the symbol to be exported by the c++utilities library.
static constexpr TimeSpan fromMinutes(double minutes)
Constructs a new instance of the TimeSpan class with the specified number of minutes.