1#ifndef CHRONO_UTILITIES_TIMESPAN_H
2#define CHRONO_UTILITIES_TIMESPAN_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#ifdef CHRONO_UTILITIES_TIMESPAN_INTEGER_SCALE_OVERLOADS
46 static TimeSpan fromString(
const std::string &str,
char separator =
':');
47 static TimeSpan fromString(
const char *str,
char separator);
48 static constexpr TimeSpan negativeInfinity();
49 static constexpr TimeSpan infinity();
52 constexpr TickType totalTicks()
const;
53 constexpr double totalMicroseconds()
const;
54 constexpr double totalMilliseconds()
const;
55 constexpr double totalSeconds()
const;
56 constexpr double totalMinutes()
const;
57 constexpr double totalHours()
const;
58 constexpr double totalDays()
const;
60 constexpr int nanoseconds()
const;
61 constexpr int microseconds()
const;
62 constexpr int milliseconds()
const;
63 constexpr int seconds()
const;
64 constexpr int minutes()
const;
65 constexpr int hours()
const;
66 constexpr int days()
const;
69 constexpr bool operator!=(
const TimeSpan &other)
const;
70 constexpr bool operator<(
const TimeSpan &other)
const;
71 constexpr bool operator>(
const TimeSpan &other)
const;
72 constexpr bool operator<=(
const TimeSpan &other)
const;
73 constexpr bool operator>=(
const TimeSpan &other)
const;
76 constexpr TimeSpan operator*(
double factor)
const;
77 constexpr TimeSpan operator/(
double factor)
const;
78#ifdef CHRONO_UTILITIES_TIMESPAN_INTEGER_SCALE_OVERLOADS
82 constexpr double operator/(
TimeSpan other)
const;
87#ifdef CHRONO_UTILITIES_TIMESPAN_INTEGER_SCALE_OVERLOADS
92 std::string toString(
TimeSpanOutputFormat format = TimeSpanOutputFormat::Normal,
bool fullSeconds =
false)
const;
93 void toString(std::string &result,
TimeSpanOutputFormat format = TimeSpanOutputFormat::Normal,
bool fullSeconds =
false)
const;
94 constexpr bool isNull()
const;
95 constexpr bool isNegative()
const;
96 constexpr bool isNegativeInfinity()
const;
97 constexpr bool isInfinity()
const;
99 static constexpr TickType nanosecondsPerTick = 100L;
100 static constexpr TickType ticksPerMicrosecond = 10L;
101 static constexpr TickType ticksPerMillisecond = 10000L;
102 static constexpr TickType ticksPerSecond = 10000000L;
103 static constexpr TickType ticksPerMinute = 600000000L;
104 static constexpr TickType ticksPerHour = 36000000000L;
105 static constexpr TickType ticksPerDay = 864000000000L;
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.
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