28 #ifndef V8_PLATFORM_TIME_H_
29 #define V8_PLATFORM_TIME_H_
34 #include "../allocation.h"
61 static TimeDelta FromDays(
int days);
62 static TimeDelta FromHours(
int hours);
63 static TimeDelta FromMinutes(
int minutes);
64 static TimeDelta FromSeconds(int64_t seconds);
65 static TimeDelta FromMilliseconds(int64_t milliseconds);
67 return TimeDelta(microseconds);
69 static TimeDelta FromNanoseconds(int64_t nanoseconds);
78 int InMinutes()
const;
79 double InSecondsF()
const;
80 int64_t InSeconds()
const;
81 double InMillisecondsF()
const;
82 int64_t InMilliseconds()
const;
83 int64_t InMillisecondsRoundedUp()
const;
85 int64_t InNanoseconds()
const;
88 static TimeDelta FromMachTimespec(
struct mach_timespec ts);
89 struct mach_timespec ToMachTimespec() const;
92 static TimeDelta FromTimespec(
struct timespec ts);
93 struct timespec ToTimespec() const;
96 delta_ = other.delta_;
102 return TimeDelta(delta_ + other.delta_);
105 return TimeDelta(delta_ - other.delta_);
109 delta_ += other.delta_;
113 delta_ -= other.delta_;
117 return TimeDelta(-delta_);
120 double TimesOf(
const TimeDelta& other)
const {
121 return static_cast<double>(delta_) / static_cast<double>(other.delta_);
124 return TimesOf(other) * 100.0;
130 return TimeDelta(delta_ * a);
133 return TimeDelta(delta_ / a);
144 return delta_ / other.delta_;
149 return delta_ == other.delta_;
152 return delta_ != other.delta_;
155 return delta_ < other.delta_;
158 return delta_ <= other.delta_;
161 return delta_ > other.delta_;
164 return delta_ >= other.delta_;
171 explicit TimeDelta(int64_t delta) : delta_(delta) {}
186 static const int64_t kMillisecondsPerSecond = 1000;
187 static const int64_t kMicrosecondsPerMillisecond = 1000;
188 static const int64_t kMicrosecondsPerSecond = kMicrosecondsPerMillisecond *
189 kMillisecondsPerSecond;
190 static const int64_t kMicrosecondsPerMinute = kMicrosecondsPerSecond * 60;
191 static const int64_t kMicrosecondsPerHour = kMicrosecondsPerMinute * 60;
192 static const int64_t kMicrosecondsPerDay = kMicrosecondsPerHour * 24;
193 static const int64_t kMicrosecondsPerWeek = kMicrosecondsPerDay * 7;
194 static const int64_t kNanosecondsPerMicrosecond = 1000;
195 static const int64_t kNanosecondsPerSecond = kNanosecondsPerMicrosecond *
196 kMicrosecondsPerSecond;
205 bool IsMax()
const {
return us_ == std::numeric_limits<int64_t>::max(); }
216 static Time NowFromSystemTime();
223 static Time
Max() {
return Time(std::numeric_limits<int64_t>::max()); }
235 static Time FromTimespec(
struct timespec ts);
236 struct timespec ToTimespec() const;
239 static Time FromTimeval(
struct timeval tv);
240 struct timeval ToTimeval() const;
243 static Time FromFiletime(
struct _FILETIME ft);
244 struct _FILETIME ToFiletime() const;
248 static Time FromJsTime(
double ms_since_epoch);
249 double ToJsTime()
const;
258 return TimeDelta::FromMicroseconds(us_ - other.us_);
263 us_ += delta.InMicroseconds();
267 us_ -= delta.InMicroseconds();
273 return Time(us_ + delta.InMicroseconds());
276 return Time(us_ - delta.InMicroseconds());
281 return us_ == other.us_;
284 return us_ != other.us_;
287 return us_ < other.us_;
290 return us_ <= other.us_;
293 return us_ > other.us_;
296 return us_ >= other.us_;
300 explicit Time(int64_t us) : us_(us) {}
306 inline Time
operator+(
const TimeDelta& delta,
const Time& time) {
329 static TimeTicks Now();
336 static TimeTicks HighResolutionNow();
339 static bool IsHighResolutionClockWorking();
342 bool IsNull()
const {
return ticks_ == 0; }
347 return TimeTicks(value);
354 ticks_ = other.ticks_;
360 return TimeDelta::FromMicroseconds(ticks_ - other.ticks_);
365 ticks_ += delta.InMicroseconds();
369 ticks_ -= delta.InMicroseconds();
375 return TimeTicks(ticks_ + delta.InMicroseconds());
378 return TimeTicks(ticks_ - delta.InMicroseconds());
383 return ticks_ == other.ticks_;
386 return ticks_ != other.ticks_;
389 return ticks_ < other.ticks_;
392 return ticks_ <= other.ticks_;
395 return ticks_ > other.ticks_;
398 return ticks_ >= other.ticks_;
404 explicit TimeTicks(int64_t ticks) : ticks_(ticks) {}
410 inline TimeTicks
operator+(
const TimeDelta& delta,
const TimeTicks& ticks) {
411 return ticks + delta;
416 #endif // V8_PLATFORM_TIME_H_
double TimesOf(const TimeDelta &other) const
TimeDelta operator/(int64_t a) const
int64_t operator/(const TimeDelta &other) const
TimeDelta & operator*=(int64_t a)
TimeDelta & operator/=(int64_t a)
Time operator+(const TimeDelta &delta, const Time &time)
bool operator>(const TimeTicks &other) const
Time & operator+=(const TimeDelta &delta)
TimeDelta operator-() const
bool operator>(const Time &other) const
TimeDelta operator*(int64_t a) const
static Time FromInternalValue(int64_t value)
bool operator>=(const TimeTicks &other) const
static TimeTicks FromInternalValue(int64_t value)
bool operator==(const Time &other) const
TimeTicks operator+(const TimeDelta &delta) const
bool operator<(const TimeDelta &other) const
int64_t InMicroseconds() const
bool operator==(const TimeDelta &other) const
TimeTicks & operator+=(const TimeDelta &delta)
bool operator<(const TimeTicks &other) const
bool operator!=(const TimeTicks &other) const
double PercentOf(const TimeDelta &other) const
TimeDelta operator-(const TimeDelta &other) const
TimeDelta operator-(const TimeTicks other) const
bool operator<=(const TimeDelta &other) const
Time & operator=(const Time &other)
bool operator!=(const Time &other) const
TimeTicks operator-(const TimeDelta &delta) const
bool operator>=(const Time &other) const
bool operator<(const Time &other) const
TimeDelta & operator-=(const TimeDelta &other)
bool operator==(const TimeTicks &other) const
TimeTicks & operator-=(const TimeDelta &delta)
TimeDelta & operator=(const TimeDelta &other)
TimeTicks & operator=(const TimeTicks other)
Time & operator-=(const TimeDelta &delta)
Time operator+(const TimeDelta &delta) const
TimeDelta operator-(const Time &other) const
Time operator-(const TimeDelta &delta) const
static TimeDelta FromMicroseconds(int64_t microseconds)
bool operator<=(const TimeTicks &other) const
TimeDelta & operator+=(const TimeDelta &other)
bool operator!=(const TimeDelta &other) const
bool operator>=(const TimeDelta &other) const
TimeDelta operator+(const TimeDelta &other) const
int64_t ToInternalValue() const
bool operator<=(const Time &other) const
bool operator>(const TimeDelta &other) const