#ifndef WTF_MonotonicTime_h
#define WTF_MonotonicTime_h
#include <wtf/ClockType.h>
#include <wtf/Seconds.h>
namespace WTF {
class WallTime;
class PrintStream;
class MonotonicTime {
public:
static const ClockType clockType = ClockType::Monotonic;
constexpr MonotonicTime() { }
static constexpr MonotonicTime fromRawSeconds(double value)
{
return MonotonicTime(value);
}
WTF_EXPORT_PRIVATE static MonotonicTime now();
static constexpr MonotonicTime infinity() { return fromRawSeconds(std::numeric_limits<double>::infinity()); }
static constexpr MonotonicTime nan() { return fromRawSeconds(std::numeric_limits<double>::quiet_NaN()); }
constexpr Seconds secondsSinceEpoch() const { return Seconds(m_value); }
MonotonicTime approximateMonotonicTime() const { return *this; }
WTF_EXPORT_PRIVATE WallTime approximateWallTime() const;
explicit constexpr operator bool() const { return !!m_value; }
constexpr MonotonicTime operator+(Seconds other) const
{
return fromRawSeconds(m_value + other.value());
}
constexpr MonotonicTime operator-(Seconds other) const
{
return fromRawSeconds(m_value - other.value());
}
Seconds operator%(Seconds other) const
{
return Seconds { fmod(m_value, other.value()) };
}
constexpr MonotonicTime operator-() const
{
return fromRawSeconds(-m_value);
}
MonotonicTime operator+=(Seconds other)
{
return *this = *this + other;
}
MonotonicTime operator-=(Seconds other)
{
return *this = *this - other;
}
constexpr Seconds operator-(MonotonicTime other) const
{
return Seconds(m_value - other.m_value);
}
constexpr bool operator==(MonotonicTime other) const
{
return m_value == other.m_value;
}
constexpr bool operator!=(MonotonicTime other) const
{
return m_value != other.m_value;
}
constexpr bool operator<(MonotonicTime other) const
{
return m_value < other.m_value;
}
constexpr bool operator>(MonotonicTime other) const
{
return m_value > other.m_value;
}
constexpr bool operator<=(MonotonicTime other) const
{
return m_value <= other.m_value;
}
constexpr bool operator>=(MonotonicTime other) const
{
return m_value >= other.m_value;
}
WTF_EXPORT_PRIVATE void dump(PrintStream&) const;
MonotonicTime isolatedCopy() const
{
return *this;
}
private:
constexpr MonotonicTime(double rawValue)
: m_value(rawValue)
{
}
double m_value { 0 };
};
}
namespace std {
inline bool isnan(WTF::MonotonicTime time)
{
return std::isnan(time.secondsSinceEpoch().value());
}
inline bool isinf(WTF::MonotonicTime time)
{
return std::isinf(time.secondsSinceEpoch().value());
}
inline bool isfinite(WTF::MonotonicTime time)
{
return std::isfinite(time.secondsSinceEpoch().value());
}
}
using WTF::MonotonicTime;
#endif // WTF_MonotonicTime_h