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 totalMicroseconds()
const;
46 constexpr
double totalMilliseconds()
const;
47 constexpr
double totalSeconds()
const;
48 constexpr
double totalMinutes()
const;
49 constexpr
double totalHours()
const;
50 constexpr
double totalDays()
const;
52 constexpr
int nanoseconds()
const;
53 constexpr
int microseconds()
const;
54 constexpr
int milliseconds()
const;
55 constexpr
int seconds()
const;
56 constexpr
int minutes()
const;
57 constexpr
int hours()
const;
58 constexpr
int days()
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;
65 constexpr
bool operator>=(
const TimeSpan &other)
const;
73 constexpr
bool isNull()
const;
74 constexpr
bool isNegative()
const;
75 constexpr
bool isNegativeInfinity()
const;
76 constexpr
bool isInfinity()
const;
79 static constexpr
int64 nanosecondsPerTick = 100uL;
80 static constexpr
int64 ticksPerMicrosecond = 10uL;
81 static constexpr
uint64 ticksPerMillisecond = 10000uL;
82 static constexpr
uint64 ticksPerSecond = 10000000uL;
83 static constexpr
uint64 ticksPerMinute = 600000000uL;
84 static constexpr
uint64 ticksPerHour = 36000000000uL;
85 static constexpr
uint64 ticksPerDay = 864000000000uL;
88 static constexpr
int64 m_ticksPerMillisecond = 10000L;
89 static constexpr
int64 m_ticksPerSecond = 10000000L;
90 static constexpr
int64 m_ticksPerMinute = 600000000L;
91 static constexpr
int64 m_ticksPerHour = 36000000000L;
92 static constexpr
int64 m_ticksPerDay = 864000000000L;
119 return TimeSpan(static_cast<int64>(milliseconds * static_cast<double>(m_ticksPerMillisecond)));
127 return TimeSpan(static_cast<int64>(seconds * static_cast<double>(m_ticksPerSecond)));
135 return TimeSpan(static_cast<int64>(minutes * static_cast<double>(m_ticksPerMinute)));
143 return TimeSpan(static_cast<int64>(hours * static_cast<double>(m_ticksPerHour)));
151 return TimeSpan(static_cast<int64>(days * static_cast<double>(m_ticksPerDay)));
167 return TimeSpan(std::numeric_limits<decltype(m_ticks)>::min());
175 return TimeSpan(std::numeric_limits<decltype(m_ticks)>::max());
199 return static_cast<double>(m_ticks) / static_cast<double>(m_ticksPerMillisecond);
207 return static_cast<double>(m_ticks) / static_cast<double>(m_ticksPerSecond);
215 return static_cast<double>(m_ticks) / static_cast<double>(m_ticksPerMinute);
223 return static_cast<double>(m_ticks) / static_cast<double>(m_ticksPerHour);
231 return static_cast<double>(m_ticks) / static_cast<double>(m_ticksPerDay);
257 return (m_ticks / m_ticksPerMillisecond) % 1000l;
265 return (m_ticks / m_ticksPerSecond) % 60l;
273 return (m_ticks / m_ticksPerMinute) % 60l;
281 return (m_ticks / m_ticksPerHour) % 24l;
289 return (m_ticks / m_ticksPerDay);
297 return m_ticks == other.m_ticks;
305 return m_ticks != other.m_ticks;
313 return m_ticks < other.m_ticks;
321 return m_ticks > other.m_ticks;
329 return m_ticks <= other.m_ticks;
337 return m_ticks >= other.m_ticks;
345 return TimeSpan(m_ticks + other.m_ticks);
353 return TimeSpan(m_ticks - other.m_ticks);
361 m_ticks += other.m_ticks;
370 m_ticks -= other.m_ticks;
395 return m_ticks == std::numeric_limits<decltype(m_ticks)>::min();
403 return m_ticks == std::numeric_limits<decltype(m_ticks)>::max();
416 #endif // CHRONO_UTILITIES_TIMESPAN_H constexpr int nanoseconds() const
Gets the nanoseconds component of the time interval represented by the current TimeSpan class...
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 double totalMicroseconds() const
Gets the value of the current TimeSpan class expressed in whole and fractional microseconds.
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
static constexpr int64 ticksPerMicrosecond
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...
static constexpr int64 nanosecondsPerTick
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 int microseconds() const
Gets the microseconds 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.