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