1 #ifndef CHRONO_UTILITIES_TIMESPAN_H 2 #define CHRONO_UTILITIES_TIMESPAN_H 4 #include "../conversion/types.h" 35 static constexpr
TimeSpan fromMilliseconds(
double milliseconds);
36 static constexpr
TimeSpan fromSeconds(
double seconds);
37 static constexpr
TimeSpan fromMinutes(
double minutes);
38 static constexpr
TimeSpan fromHours(
double hours);
39 static constexpr
TimeSpan fromDays(
double days);
40 static TimeSpan fromString(
const std::string &str,
char separator =
':');
41 static TimeSpan fromString(
const char *str,
char separator);
42 static constexpr
TimeSpan negativeInfinity();
43 static constexpr
TimeSpan infinity();
46 constexpr
int64 totalTicks()
const;
47 constexpr
double totalMicroseconds()
const;
48 constexpr
double totalMilliseconds()
const;
49 constexpr
double totalSeconds()
const;
50 constexpr
double totalMinutes()
const;
51 constexpr
double totalHours()
const;
52 constexpr
double totalDays()
const;
54 constexpr
int nanoseconds()
const;
55 constexpr
int microseconds()
const;
56 constexpr
int milliseconds()
const;
57 constexpr
int seconds()
const;
58 constexpr
int minutes()
const;
59 constexpr
int hours()
const;
60 constexpr
int days()
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;
66 constexpr
bool operator<=(
const TimeSpan &other)
const;
67 constexpr
bool operator>=(
const TimeSpan &other)
const;
75 constexpr
bool isNull()
const;
76 constexpr
bool isNegative()
const;
77 constexpr
bool isNegativeInfinity()
const;
78 constexpr
bool isInfinity()
const;
81 static constexpr
int64 nanosecondsPerTick = 100uL;
82 static constexpr
int64 ticksPerMicrosecond = 10uL;
83 static constexpr
uint64 ticksPerMillisecond = 10000uL;
84 static constexpr
uint64 ticksPerSecond = 10000000uL;
85 static constexpr
uint64 ticksPerMinute = 600000000uL;
86 static constexpr
uint64 ticksPerHour = 36000000000uL;
87 static constexpr
uint64 ticksPerDay = 864000000000uL;
90 static constexpr
int64 m_ticksPerMillisecond = 10000L;
91 static constexpr
int64 m_ticksPerSecond = 10000000L;
92 static constexpr
int64 m_ticksPerMinute = 600000000L;
93 static constexpr
int64 m_ticksPerHour = 36000000000L;
94 static constexpr
int64 m_ticksPerDay = 864000000000L;
129 return TimeSpan(static_cast<int64>(
seconds * static_cast<double>(m_ticksPerSecond)));
137 return TimeSpan(static_cast<int64>(
minutes * static_cast<double>(m_ticksPerMinute)));
145 return TimeSpan(static_cast<int64>(
hours * static_cast<double>(m_ticksPerHour)));
153 return TimeSpan(static_cast<int64>(
days * static_cast<double>(m_ticksPerDay)));
174 return TimeSpan(std::numeric_limits<decltype(m_ticks)>::
min());
182 return TimeSpan(std::numeric_limits<decltype(m_ticks)>::
max());
214 return static_cast<double>(m_ticks) / static_cast<double>(m_ticksPerMillisecond);
222 return static_cast<double>(m_ticks) / static_cast<double>(m_ticksPerSecond);
230 return static_cast<double>(m_ticks) / static_cast<double>(m_ticksPerMinute);
238 return static_cast<double>(m_ticks) / static_cast<double>(m_ticksPerHour);
246 return static_cast<double>(m_ticks) / static_cast<double>(m_ticksPerDay);
272 return (m_ticks / m_ticksPerMillisecond) % 1000l;
280 return (m_ticks / m_ticksPerSecond) % 60l;
288 return (m_ticks / m_ticksPerMinute) % 60l;
296 return (m_ticks / m_ticksPerHour) % 24l;
304 return (m_ticks / m_ticksPerDay);
312 return m_ticks == other.m_ticks;
320 return m_ticks != other.m_ticks;
328 return m_ticks < other.m_ticks;
336 return m_ticks > other.m_ticks;
344 return m_ticks <= other.m_ticks;
352 return m_ticks >= other.m_ticks;
360 return TimeSpan(m_ticks + other.m_ticks);
368 return TimeSpan(m_ticks - other.m_ticks);
376 m_ticks += other.m_ticks;
385 m_ticks -= other.m_ticks;
410 return m_ticks == std::numeric_limits<decltype(m_ticks)>
::min();
418 return m_ticks == std::numeric_limits<decltype(m_ticks)>
::max();
431 #endif // CHRONO_UTILITIES_TIMESPAN_H constexpr int nanoseconds() const
Returns the nanoseconds component of the time interval represented by the current TimeSpan class.
DateTime CPP_UTILITIES_EXPORT operator+(DateTime begin, Period period)
Adds the specified period to the specified date.
TimeSpanOutputFormat
Specifies the output format.
constexpr double totalMilliseconds() const
Returns 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.
#define CPP_UTILITIES_EXPORT
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
Returns the number of ticks that represent the value of the current TimeSpan class.
constexpr int days() const
Returns the days component of the time interval represented by the current TimeSpan class.
constexpr double totalMinutes() const
Returns the value of the current TimeSpan class expressed in whole and fractional minutes.
Represents a time interval.
constexpr int hours() const
Returns 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
Returns 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
Returns 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 T max(T first, T second)
Returns the greatest of the given items.
constexpr bool operator>=(const TimeSpan &other) const
Indicates whether a specified TimeSpan is greater or equal than another specified TimeSpan.
static constexpr int64 nanosecondsPerTick
int64 & ticks()
Returns a mutable reference to the total ticks.
constexpr bool operator<(const TimeSpan &other) const
Indicates whether a specified TimeSpan is less than another specified TimeSpan.
constexpr int minutes() const
Returns 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
Returns 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
Returns 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.
constexpr T min(T first, T second)
Returns the smallest of the given items.
TimeSpan & operator+=(const TimeSpan &other)
Adds another TimeSpan to the current instance.
constexpr int seconds() const
Returns the seconds component of the time interval represented by the current TimeSpan class.
constexpr int microseconds() const
Returns 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.
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 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.
static constexpr TimeSpan fromMinutes(double minutes)
Constructs a new instance of the TimeSpan class with the specified number of minutes.