30 nanoseconds_ =
static_cast<int64_t
>(nanoseconds);
34 nanoseconds_ =
static_cast<int64_t
>(seconds * 1000000000UL);
38 nanoseconds_ =
static_cast<uint64_t
>(seconds) * 1000000000UL + nanoseconds;
44 this->nanoseconds_ = other.nanoseconds_;
49 return static_cast<double>(nanoseconds_) / 1000000000UL;
57 auto sleep_time = std::chrono::nanoseconds(nanoseconds_);
58 std::this_thread::sleep_for(sleep_time);
62 return Duration(nanoseconds_ + rhs.nanoseconds_);
66 return Duration(nanoseconds_ - rhs.nanoseconds_);
72 return Duration(int64_t(
static_cast<double>(nanoseconds_) * scale));
86 *
this =
Duration(int64_t(
static_cast<double>(nanoseconds_) * scale));
91 return nanoseconds_ == rhs.nanoseconds_;
95 return nanoseconds_ != rhs.nanoseconds_;
99 return nanoseconds_ > rhs.nanoseconds_;
103 return nanoseconds_ < rhs.nanoseconds_;
107 return nanoseconds_ >= rhs.nanoseconds_;
111 return nanoseconds_ <= rhs.nanoseconds_;
115 std::ios::fmtflags before(os.flags());
116 os << std::fixed << std::setprecision(9) << rhs.
ToSecond() <<
"s";
bool operator!=(const Duration &rhs) const
Duration & operator=(const Duration &other)
Duration operator-() const
bool operator>=(const Duration &rhs) const
Duration & operator-=(const Duration &rhs)
bool operator>(const Duration &rhs) const
Duration operator+(const Duration &rhs) const
Duration operator*(double scale) const
Duration & operator*=(double scale)
int64_t ToNanosecond() const
bool operator==(const Duration &rhs) const
bool operator<=(const Duration &rhs) const
bool operator<(const Duration &rhs) const
Duration & operator+=(const Duration &rhs)
std::ostream & operator<<(std::ostream &os, const Duration &rhs)