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;
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);
290 return static_cast<int>((m_ticks /
ticksPerHour) % 24l);
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);
370 return TimeSpan(
static_cast<std::int64_t
>(
static_cast<double>(m_ticks) * factor));
378 return TimeSpan(
static_cast<std::int64_t
>(
static_cast<double>(m_ticks) / factor));
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 =
static_cast<std::int64_t
>(
static_cast<double>(m_ticks) * factor);
421 m_ticks =
static_cast<std::int64_t
>(
static_cast<double>(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();
Represents an instant in time, typically expressed as a date and time of day.
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 ticksPerMinute
constexpr double totalSeconds() const
Returns the value of the current TimeSpan class expressed in whole and fractional seconds.
constexpr bool isNull() const
Returns true 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 less than another specified TimeSpan.
constexpr TimeSpan operator*(double factor) const
Multiplies a TimeSpan by the specified factor.
static constexpr std::int64_t ticksPerDay
constexpr bool operator!=(const TimeSpan &other) const
Indicates whether two TimeSpan instances are not equal.
constexpr int seconds() const
Returns the seconds component of the time interval represented by the current TimeSpan class.
constexpr std::int64_t totalTicks() const
Returns the number of ticks that represent the value of the current TimeSpan class.
TimeSpan & operator*=(double factor)
Multiplies the current instance by the specified factor.
constexpr bool isNegativeInfinity() const
Returns whether the time interval represented by the current instance is the smallest representable T...
static constexpr std::int64_t ticksPerSecond
constexpr int minutes() const
Returns the minutes component of the time interval represented by the current TimeSpan class.
constexpr double totalMicroseconds() const
Returns the value of the current TimeSpan class expressed in whole and fractional microseconds.
constexpr TimeSpan operator/(double factor) const
Divides a TimeSpan by the specified factor.
constexpr TimeSpan()
Constructs a new instance of the TimeSpan class with zero ticks.
constexpr bool operator>(const TimeSpan &other) const
Indicates whether a specified TimeSpan is greater than another specified TimeSpan.
static constexpr std::int64_t nanosecondsPerTick
constexpr bool operator==(const TimeSpan &other) const
Indicates whether two TimeSpan instances are equal.
constexpr int days() const
Returns the days component of the time interval represented by the current TimeSpan class.
std::int64_t & ticks()
Returns a mutable reference to the total ticks.
constexpr int milliseconds() const
Returns the milliseconds component of the time interval represented by the current TimeSpan class.
static constexpr std::int64_t ticksPerHour
constexpr TimeSpan operator-(const TimeSpan &other) const
Subtracts one TimeSpan instance from another.
constexpr bool operator>=(const TimeSpan &other) const
Indicates whether a specified TimeSpan is greater or equal than another specified TimeSpan.
TimeSpan & operator+=(const TimeSpan &other)
Adds another TimeSpan to the current instance.
static constexpr TimeSpan fromDays(double days)
Constructs a new instance of the TimeSpan class with the specified number of days.
static constexpr TimeSpan fromHours(double hours)
Constructs a new instance of the TimeSpan class with the specified number of hours.
static constexpr TimeSpan fromMinutes(double minutes)
Constructs a new instance of the TimeSpan class with the specified number of minutes.
static constexpr TimeSpan infinity()
Constructs a new instance of the TimeSpan class with the maximal number of ticks.
static constexpr TimeSpan fromSeconds(double seconds)
Constructs a new instance of the TimeSpan class with the specified number of seconds.
constexpr bool isInfinity() const
Returns whether the time interval represented by the current instance is the longest representable Ti...
static constexpr TimeSpan negativeInfinity()
Constructs a new instance of the TimeSpan class with the minimal number of ticks.
static constexpr std::int64_t ticksPerMicrosecond
constexpr int microseconds() const
Returns the microseconds component of the time interval represented by the current TimeSpan class.
constexpr double totalDays() const
Returns the value of the current TimeSpan class expressed in whole and fractional days.
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...
static TimeSpan fromString(const std::string &str, char separator=':')
Parses the given std::string as TimeSpan.
constexpr double totalMilliseconds() const
Returns the value of the current TimeSpan class expressed in whole and fractional milliseconds.
constexpr bool isNegative() const
Returns true if the time interval represented by the current TimeSpan class is negative.
static constexpr std::int64_t ticksPerMillisecond
constexpr int hours() const
Returns the hours component of the time interval represented by the current TimeSpan class.
constexpr TimeSpan operator+(const TimeSpan &other) const
Adds two TimeSpan instances.
constexpr double totalMinutes() const
Returns the value of the current TimeSpan class expressed in whole and fractional minutes.
constexpr bool operator<=(const TimeSpan &other) const
Indicates whether a specified TimeSpan is less or equal than another specified TimeSpan.
TimeSpan & operator/=(double factor)
Divides the current instance by the specified factor.
TimeSpan & operator-=(const TimeSpan &other)
Subtracts another TimeSpan from the current instance.
constexpr int nanoseconds() const
Returns the nanoseconds 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 milliseconds.
#define CPP_UTILITIES_EXPORT
Marks the symbol to be exported by the c++utilities library.
constexpr FlagEnumClass & operator-=(FlagEnumClass &lhs, FlagEnumClass rhs)
constexpr FlagEnumClass & operator+=(FlagEnumClass &lhs, FlagEnumClass rhs)
Contains all utilities provides by the c++utilities library.
CPP_UTILITIES_EXPORT DateTime operator+(DateTime begin, Period period)
Adds the specified period to the specified date.
TimeSpanOutputFormat
Specifies the output format.
bool operator==(const AsHexNumber< T > &lhs, const AsHexNumber< T > &rhs)
Provides operator == required by CPPUNIT_ASSERT_EQUAL.
constexpr T max(T first, T second)
Returns the greatest of the given items.
constexpr T min(T first, T second)
Returns the smallest of the given items.
size_t operator()(const CppUtilities::TimeSpan &timeSpan) const