C++ Utilities
5.6.0
Useful C++ classes and routines such as argument parser, IO and conversion utilities
|
Go to the documentation of this file. 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;
72 constexpr
bool isNull()
const;
73 constexpr
bool isNegative()
const;
74 constexpr
bool isNegativeInfinity()
const;
75 constexpr
bool isInfinity()
const;
77 static constexpr std::int64_t nanosecondsPerTick = 100uL;
78 static constexpr std::int64_t ticksPerMicrosecond = 10uL;
79 static constexpr std::int64_t ticksPerMillisecond = 10000uL;
80 static constexpr std::int64_t ticksPerSecond = 10000000uL;
81 static constexpr std::int64_t ticksPerMinute = 600000000uL;
82 static constexpr std::int64_t ticksPerHour = 36000000000uL;
83 static constexpr std::int64_t ticksPerDay = 864000000000uL;
163 return TimeSpan(std::numeric_limits<decltype(m_ticks)>::
min());
171 return TimeSpan(std::numeric_limits<decltype(m_ticks)>::
max());
211 return static_cast<double>(m_ticks) /
static_cast<double>(
ticksPerSecond);
219 return static_cast<double>(m_ticks) /
static_cast<double>(
ticksPerMinute);
227 return static_cast<double>(m_ticks) /
static_cast<double>(
ticksPerHour);
235 return static_cast<double>(m_ticks) /
static_cast<double>(
ticksPerDay);
301 return m_ticks == other.m_ticks;
309 return m_ticks != other.m_ticks;
317 return m_ticks < other.m_ticks;
325 return m_ticks > other.m_ticks;
333 return m_ticks <= other.m_ticks;
341 return m_ticks >= other.m_ticks;
349 return TimeSpan(m_ticks + other.m_ticks);
357 return TimeSpan(m_ticks - other.m_ticks);
365 m_ticks += other.m_ticks;
374 m_ticks -= other.m_ticks;
387 toString(result, format, fullSeconds);
412 return m_ticks == std::numeric_limits<decltype(m_ticks)>
::min();
420 return m_ticks == std::numeric_limits<decltype(m_ticks)>
::max();
434 #endif // CHRONO_UTILITIES_TIMESPAN_H
constexpr bool operator!=(const TimeSpan &other) const
Indicates whether two TimeSpan instances are not equal.
static constexpr std::int64_t ticksPerDay
constexpr double totalMilliseconds() const
Returns the value of the current TimeSpan class expressed in whole and fractional milliseconds.
static constexpr std::int64_t ticksPerMillisecond
constexpr bool operator<(const TimeSpan &other) const
Indicates whether a specified TimeSpan is less than another specified TimeSpan.
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.
TimeSpan & operator-=(const TimeSpan &other)
Substracts another TimeSpan from the current instance.
static constexpr TimeSpan negativeInfinity()
Constructs a new instace of the TimeSpan class with the minimal number of ticks.
CPP_UTILITIES_EXPORT DateTime operator+(DateTime begin, Period period)
Adds the specified period to the specified date.
constexpr TimeSpan()
Constructs a new instance of the TimeSpan class with zero ticks.
constexpr int milliseconds() const
Returns the miliseconds component of the time interval represented by the current TimeSpan class.
constexpr bool isNegativeInfinity() const
Returns whether the time inverval represented by the current instance is the smallest representable T...
constexpr int seconds() const
Returns the seconds component of the time interval represented by the current TimeSpan class.
static constexpr std::int64_t ticksPerMicrosecond
std::int64_t & ticks()
Returns a mutable reference to the total ticks.
static TimeSpan fromString(const std::string &str, char separator=':')
Parses the given std::string as TimeSpan.
constexpr T max(T first, T second)
Returns the greatest of the given items.
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...
constexpr bool operator>(const TimeSpan &other) const
Indicates whether a specified TimeSpan is greater than another specified TimeSpan.
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 or equal than another specified TimeSpan.
constexpr std::int64_t totalTicks() const
Returns the number of ticks that represent the value of the current TimeSpan class.
size_t operator()(const CppUtilities::TimeSpan &timeSpan) const
TimeSpanOutputFormat
Specifies the output format.
constexpr TimeSpan operator-(const TimeSpan &other) const
Substracts two TimeSpan instances.
constexpr int hours() const
Returns the hours component of the time interval represented by the current TimeSpan class.
constexpr int minutes() const
Returns the minutes component of the time interval represented by the current TimeSpan class.
Contains all utilities provides by the c++utilities library.
static constexpr std::int64_t ticksPerHour
static constexpr TimeSpan fromMinutes(double minutes)
Constructs a new instance of the TimeSpan class with the specified number of minutes.
constexpr int microseconds() const
Returns the microseconds component of the time interval represented by the current TimeSpan class.
constexpr FlagEnumClass & operator+=(FlagEnumClass &lhs, FlagEnumClass rhs)
static constexpr TimeSpan fromHours(double hours)
Constructs a new instance of the TimeSpan class with the specified number of hours.
constexpr FlagEnumClass & operator-=(FlagEnumClass &lhs, FlagEnumClass rhs)
TimeSpan & operator+=(const TimeSpan &other)
Adds another TimeSpan to the current instance.
constexpr T min(T first, T second)
Returns the smallest of the given items.
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 nanosecondsPerTick
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 two TimeSpan instances are equal.
Represents an instant in time, typically expressed as a date and time of day.
static constexpr std::int64_t ticksPerSecond
constexpr bool isInfinity() const
Returns whether the time inverval represented by the current instance is the longest representable Ti...
#define CPP_UTILITIES_EXPORT
Marks the symbol to be exported by the c++utilities library.
static constexpr TimeSpan infinity()
Constructs a new instace of the TimeSpan class with the maximal number of ticks.
constexpr double totalMinutes() const
Returns the value of the current TimeSpan class expressed in whole and fractional minutes.
bool operator==(const AsHexNumber< T > &lhs, const AsHexNumber< T > &rhs)
Provides operator == required by CPPUNIT_ASSERT_EQUAL.
static constexpr std::int64_t ticksPerMinute
constexpr int nanoseconds() const
Returns the nanoseconds component of the time interval represented by the current TimeSpan class.
constexpr TimeSpan operator+(const TimeSpan &other) const
Adds two TimeSpan instances.
static constexpr TimeSpan fromSeconds(double seconds)
Constructs a new instance of the TimeSpan class with the specified number of seconds.
constexpr bool operator<=(const TimeSpan &other) const
Indicates whether a specified TimeSpan is less or equal than another specified TimeSpan.
constexpr bool isNull() const
Returns ture if the time interval represented by the current TimeSpan class is null.
static constexpr TimeSpan fromDays(double days)
Constructs a new instance of the TimeSpan class with the specified number of days.
constexpr int days() const
Returns the days component of the time interval represented by the current TimeSpan class.
constexpr double totalSeconds() const
Returns the value of the current TimeSpan class expressed in whole and fractional seconds.