/* */ #include "TimerA2.h" namespace aria2 { // Add this offset to Timer::Clock::now() so that we can treat 0 value // as special case, and normal timeout always applies. constexpr auto OFFSET = 24_h; namespace { Timer::Clock::time_point getNow() { return Timer::Clock::now() + OFFSET; } } // namespace Timer::Timer() : tp_(getNow()) { reset(); } Timer::Timer(const Clock::time_point& tp) : tp_(tp) {} void Timer::reset() { tp_ = getNow(); } Timer::Clock::duration Timer::difference() const { auto now = getNow(); if (now < tp_) { return Timer::Clock::duration(0_s); } return now - tp_; } Timer::Clock::duration Timer::difference(const Timer& timer) const { if (timer.tp_ < tp_) { return Timer::Clock::duration(0_s); } return timer.tp_ - tp_; } bool Timer::isZero() const { return tp_.time_since_epoch() == Clock::duration::zero(); } } // namespace aria2