Lines Matching +full:- +full:- +full:max +full:- +full:time
2 // Use of this source code is governed by a BSD-style license that can be
5 #include "base/time/time.h"
18 #include "base/time/time_override.h"
38 // TimeDelta ------------------------------------------------------------------
42 // Preserve max to prevent overflow. in InDays()
43 return std::numeric_limits<int>::max(); in InDays()
45 return static_cast<int>(delta_ / Time::kMicrosecondsPerDay); in InDays()
50 // Preserve max to prevent overflow. in InDaysFloored()
51 return std::numeric_limits<int>::max(); in InDaysFloored()
53 int result = delta_ / Time::kMicrosecondsPerDay; in InDaysFloored()
54 int64_t remainder = delta_ - (result * Time::kMicrosecondsPerDay); in InDaysFloored()
56 --result; // Use floor(), not trunc() rounding behavior. in InDaysFloored()
63 // Preserve max to prevent overflow. in InHours()
64 return std::numeric_limits<int>::max(); in InHours()
66 return static_cast<int>(delta_ / Time::kMicrosecondsPerHour); in InHours()
71 // Preserve max to prevent overflow. in InMinutes()
72 return std::numeric_limits<int>::max(); in InMinutes()
74 return static_cast<int>(delta_ / Time::kMicrosecondsPerMinute); in InMinutes()
79 // Preserve max to prevent overflow. in InSecondsF()
82 return static_cast<double>(delta_) / Time::kMicrosecondsPerSecond; in InSecondsF()
87 // Preserve max to prevent overflow. in InSeconds()
88 return std::numeric_limits<int64_t>::max(); in InSeconds()
90 return delta_ / Time::kMicrosecondsPerSecond; in InSeconds()
95 // Preserve max to prevent overflow. in InMillisecondsF()
98 return static_cast<double>(delta_) / Time::kMicrosecondsPerMillisecond; in InMillisecondsF()
103 // Preserve max to prevent overflow. in InMilliseconds()
104 return std::numeric_limits<int64_t>::max(); in InMilliseconds()
106 return delta_ / Time::kMicrosecondsPerMillisecond; in InMilliseconds()
111 // Preserve max to prevent overflow. in InMillisecondsRoundedUp()
112 return std::numeric_limits<int64_t>::max(); in InMillisecondsRoundedUp()
114 int64_t result = delta_ / Time::kMicrosecondsPerMillisecond; in InMillisecondsRoundedUp()
115 int64_t remainder = delta_ - (result * Time::kMicrosecondsPerMillisecond); in InMillisecondsRoundedUp()
124 // Preserve max to prevent overflow. in InMicroseconds()
125 return std::numeric_limits<int64_t>::max(); in InMicroseconds()
132 // Preserve max to prevent overflow. in InMicrosecondsF()
140 // Preserve max to prevent overflow. in InNanoseconds()
141 return std::numeric_limits<int64_t>::max(); in InNanoseconds()
143 return delta_ * Time::kNanosecondsPerMicrosecond; in InNanoseconds()
156 return std::numeric_limits<int64_t>::max(); in SaturatedAdd()
161 rv -= value; in SaturatedSub()
166 return std::numeric_limits<int64_t>::max(); in SaturatedSub()
176 // Time -----------------------------------------------------------------------
179 Time Time::Now() { in Now()
184 Time Time::NowFromSystemTime() { in NowFromSystemTime()
185 // Just use g_time_now_function because it returns the system time. in NowFromSystemTime()
190 Time Time::FromDeltaSinceWindowsEpoch(TimeDelta delta) { in FromDeltaSinceWindowsEpoch()
191 return Time(delta.InMicroseconds()); in FromDeltaSinceWindowsEpoch()
194 TimeDelta Time::ToDeltaSinceWindowsEpoch() const { in ToDeltaSinceWindowsEpoch()
199 Time Time::FromTimeT(time_t tt) { in FromTimeT()
201 return Time(); // Preserve 0 so we can tell it doesn't exist. in FromTimeT()
202 if (tt == std::numeric_limits<time_t>::max()) in FromTimeT()
203 return Max(); in FromTimeT()
204 return Time(kTimeTToMicrosecondsOffset) + TimeDelta::FromSeconds(tt); in FromTimeT()
207 time_t Time::ToTimeT() const { in ToTimeT()
211 // Preserve max without offset to prevent overflow. in ToTimeT()
212 return std::numeric_limits<time_t>::max(); in ToTimeT()
214 if (std::numeric_limits<int64_t>::max() - kTimeTToMicrosecondsOffset <= us_) { in ToTimeT()
215 DLOG(WARNING) << "Overflow when converting base::Time with internal " << in ToTimeT()
217 return std::numeric_limits<time_t>::max(); in ToTimeT()
219 return (us_ - kTimeTToMicrosecondsOffset) / kMicrosecondsPerSecond; in ToTimeT()
223 Time Time::FromDoubleT(double dt) { in FromDoubleT()
225 return Time(); // Preserve 0 so we can tell it doesn't exist. in FromDoubleT()
226 return Time(kTimeTToMicrosecondsOffset) + TimeDelta::FromSecondsD(dt); in FromDoubleT()
229 double Time::ToDoubleT() const { in ToDoubleT()
233 // Preserve max without offset to prevent overflow. in ToDoubleT()
236 return (static_cast<double>(us_ - kTimeTToMicrosecondsOffset) / in ToDoubleT()
242 Time Time::FromTimeSpec(const timespec& ts) { in FromTimeSpec()
245 base::Time::kNanosecondsPerSecond); in FromTimeSpec()
250 Time Time::FromJsTime(double ms_since_epoch) { in FromJsTime()
251 // The epoch is a valid time, so this constructor doesn't interpret in FromJsTime()
252 // 0 as the null time. in FromJsTime()
253 return Time(kTimeTToMicrosecondsOffset) + in FromJsTime()
257 double Time::ToJsTime() const { in ToJsTime()
263 // Preserve max without offset to prevent overflow. in ToJsTime()
266 return (static_cast<double>(us_ - kTimeTToMicrosecondsOffset) / in ToJsTime()
270 Time Time::FromJavaTime(int64_t ms_since_epoch) { in FromJavaTime()
271 return base::Time::UnixEpoch() + in FromJavaTime()
275 int64_t Time::ToJavaTime() const { in ToJavaTime()
281 // Preserve max without offset to prevent overflow. in ToJavaTime()
282 return std::numeric_limits<int64_t>::max(); in ToJavaTime()
284 return ((us_ - kTimeTToMicrosecondsOffset) / in ToJavaTime()
289 Time Time::UnixEpoch() { in UnixEpoch()
290 Time time; in UnixEpoch() local
291 time.us_ = kTimeTToMicrosecondsOffset; in UnixEpoch()
292 return time; in UnixEpoch()
295 Time Time::LocalMidnight() const { in LocalMidnight()
302 Time out_time; in LocalMidnight()
307 return Time(); in LocalMidnight()
311 bool Time::FromStringInternal(const char* time_string, in FromStringInternal()
313 Time* parsed_time) { in FromStringInternal()
327 *parsed_time = Time(result_time); in FromStringInternal()
332 bool Time::ExplodedMostlyEquals(const Exploded& lhs, const Exploded& rhs) { in ExplodedMostlyEquals()
339 std::ostream& operator<<(std::ostream& os, Time time) { in operator <<() argument
340 Time::Exploded exploded; in operator <<()
341 time.UTCExplode(&exploded); in operator <<()
343 return os << StringPrintf("%04d-%02d-%02d %02d:%02d:%02d.%03d UTC", in operator <<()
353 // TimeTicks ------------------------------------------------------------------
363 return subtle::TimeTicksNowIgnoringOverride() - in UnixEpoch()
364 (subtle::TimeNowIgnoringOverride() - Time::UnixEpoch()); in UnixEpoch()
373 TimeDelta interval_offset = (tick_phase - *this) % tick_interval; in SnappedToNextTick()
383 // This function formats a TimeTicks object as "bogo-microseconds". in operator <<()
384 // The origin and granularity of the count are platform-specific, and may very in operator <<()
385 // from run to run. Although bogo-microseconds usually roughly correspond to in operator <<()
388 const TimeDelta as_time_delta = time_ticks - TimeTicks(); in operator <<()
389 return os << as_time_delta.InMicroseconds() << " bogo-microseconds"; in operator <<()
392 // ThreadTicks ----------------------------------------------------------------
400 const TimeDelta as_time_delta = thread_ticks - ThreadTicks(); in operator <<()
401 return os << as_time_delta.InMicroseconds() << " bogo-thread-microseconds"; in operator <<()
404 // Time::Exploded -------------------------------------------------------------
410 bool Time::Exploded::HasValidValues() const { in HasValidValues()