Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(993)

Unified Diff: base/time/time.cc

Issue 1250453004: Revert of Base: Make TimeDelta constructors deal with overflow. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « base/time/time.h ('k') | base/time/time_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/time/time.cc
diff --git a/base/time/time.cc b/base/time/time.cc
index 10ffcc606651b9a2e7ab147620d30cdb9351a443..8cbb382bb9616dfc6ed2e7f0742630845745aa62 100644
--- a/base/time/time.cc
+++ b/base/time/time.cc
@@ -144,7 +144,7 @@
return Time(); // Preserve 0 so we can tell it doesn't exist.
if (tt == std::numeric_limits<time_t>::max())
return Max();
- return Time(kTimeTToMicrosecondsOffset) + TimeDelta::FromSeconds(tt);
+ return Time((tt * kMicrosecondsPerSecond) + kTimeTToMicrosecondsOffset);
}
time_t Time::ToTimeT() const {
@@ -166,7 +166,11 @@
Time Time::FromDoubleT(double dt) {
if (dt == 0 || std::isnan(dt))
return Time(); // Preserve 0 so we can tell it doesn't exist.
- return Time(kTimeTToMicrosecondsOffset) + TimeDelta::FromSecondsD(dt);
+ if (dt == std::numeric_limits<double>::infinity())
+ return Max();
+ return Time(static_cast<int64>((dt *
+ static_cast<double>(kMicrosecondsPerSecond)) +
+ kTimeTToMicrosecondsOffset));
}
double Time::ToDoubleT() const {
@@ -193,8 +197,10 @@
Time Time::FromJsTime(double ms_since_epoch) {
// The epoch is a valid time, so this constructor doesn't interpret
// 0 as the null time.
- return Time(kTimeTToMicrosecondsOffset) +
- TimeDelta::FromMillisecondsD(ms_since_epoch);
+ if (ms_since_epoch == std::numeric_limits<double>::infinity())
+ return Max();
+ return Time(static_cast<int64>(ms_since_epoch * kMicrosecondsPerMillisecond) +
+ kTimeTToMicrosecondsOffset);
}
double Time::ToJsTime() const {
« no previous file with comments | « base/time/time.h ('k') | base/time/time_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698