1#ifndef CHRONO_UTILITIES_TIMESPAN_H
2#define CHRONO_UTILITIES_TIMESPAN_H
39#ifdef CHRONO_UTILITIES_TIMESPAN_INTEGER_SCALE_OVERLOADS
65 constexpr int hours()
const;
66 constexpr int days()
const;
78#ifdef CHRONO_UTILITIES_TIMESPAN_INTEGER_SCALE_OVERLOADS
87#ifdef CHRONO_UTILITIES_TIMESPAN_INTEGER_SCALE_OVERLOADS
94 constexpr bool isNull()
const;
167#ifdef CHRONO_UTILITIES_TIMESPAN_INTEGER_SCALE_OVERLOADS
227 return TimeSpan(std::numeric_limits<TickType>::min());
235 return TimeSpan(std::numeric_limits<TickType>::max());
275 return static_cast<double>(m_ticks) /
static_cast<double>(
ticksPerSecond);
283 return static_cast<double>(m_ticks) /
static_cast<double>(
ticksPerMinute);
291 return static_cast<double>(m_ticks) /
static_cast<double>(
ticksPerHour);
299 return static_cast<double>(m_ticks) /
static_cast<double>(
ticksPerDay);
349 return static_cast<int>((m_ticks /
ticksPerHour) % 24l);
365 return m_ticks == other.m_ticks;
373 return m_ticks != other.m_ticks;
381 return m_ticks < other.m_ticks;
389 return m_ticks > other.m_ticks;
397 return m_ticks <= other.m_ticks;
405 return m_ticks >= other.m_ticks;
413 return TimeSpan(m_ticks + other.m_ticks);
421 return TimeSpan(m_ticks - other.m_ticks);
429 return TimeSpan(
static_cast<std::int64_t
>(
static_cast<double>(m_ticks) * factor));
437 return TimeSpan(
static_cast<std::int64_t
>(
static_cast<double>(m_ticks) / factor));
440#ifdef CHRONO_UTILITIES_TIMESPAN_INTEGER_SCALE_OVERLOADS
463 return static_cast<double>(m_ticks) /
static_cast<double>(other.m_ticks);
471 m_ticks += other.m_ticks;
480 m_ticks -= other.m_ticks;
489 m_ticks =
static_cast<std::int64_t
>(
static_cast<double>(m_ticks) * factor);
498 m_ticks =
static_cast<std::int64_t
>(
static_cast<double>(m_ticks) / factor);
502#ifdef CHRONO_UTILITIES_TIMESPAN_INTEGER_SCALE_OVERLOADS
531 toString(result, format, fullSeconds);
556 return m_ticks == std::numeric_limits<
decltype(m_ticks)>
::min();
564 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.
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 TickType nanosecondsPerTick
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.
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 TickType ticksPerMillisecond
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.
constexpr TickType totalTicks() const
Returns the number of ticks that represent the value of the current TimeSpan class.
constexpr bool operator==(const TimeSpan &other) const
Indicates whether two TimeSpan instances are equal.
static constexpr TickType ticksPerMinute
constexpr int days() const
Returns the days component of the time interval represented by the current TimeSpan class.
static constexpr TickType ticksPerMicrosecond
TickType & 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.
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 TickType ticksPerSecond
static constexpr TimeSpan negativeInfinity()
Constructs a new instance of the TimeSpan class with the minimal number of ticks.
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.
static constexpr TickType ticksPerDay
constexpr double totalMilliseconds() const
Returns the value of the current TimeSpan class expressed in whole and fractional milliseconds.
static constexpr TickType ticksPerHour
constexpr bool isNegative() const
Returns true if the time interval represented by the current TimeSpan class is negative.
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.
Contains all utilities provides by the c++utilities library.
TimeSpanOutputFormat
Specifies the output format.
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