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

Unified Diff: base/time/time.h

Issue 235233003: Added support to convert double to timedelta's without loss of data during type conversion from dou… (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Added unit tests Created 6 years, 8 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 | « no previous file | base/time/time_unittest.cc » ('j') | base/time/time_unittest.cc » ('J')
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/time/time.h
diff --git a/base/time/time.h b/base/time/time.h
index 69a132431d6597514e44191a04db8bf461fb2c40..546920b2e92cac257663e7256da8cfa662f803f2 100644
--- a/base/time/time.h
+++ b/base/time/time.h
@@ -66,6 +66,8 @@ class BASE_EXPORT TimeDelta {
static TimeDelta FromMinutes(int minutes);
static TimeDelta FromSeconds(int64 secs);
static TimeDelta FromMilliseconds(int64 ms);
+ static TimeDelta FromSecondsD(double secs);
+ static TimeDelta FromMillisecondsD(double ms);
static TimeDelta FromMicroseconds(int64 us);
#if defined(OS_WIN)
static TimeDelta FromQPCValue(LONGLONG qpc_value);
@@ -543,6 +545,22 @@ inline TimeDelta TimeDelta::FromMilliseconds(int64 ms) {
}
// static
+inline TimeDelta TimeDelta::FromSecondsD(double secs) {
+ // Preserve max to prevent overflow.
+ if (secs == std::numeric_limits<double>::infinity())
+ return Max();
+ return TimeDelta(secs * Time::kMicrosecondsPerSecond);
+}
+
+// static
+inline TimeDelta TimeDelta::FromMillisecondsD(double ms) {
+ // Preserve max to prevent overflow.
+ if (ms == std::numeric_limits<double>::infinity())
+ return Max();
+ return TimeDelta(ms * Time::kMicrosecondsPerMillisecond);
+}
+
+// static
inline TimeDelta TimeDelta::FromMicroseconds(int64 us) {
// Preserve max to prevent overflow.
if (us == std::numeric_limits<int64>::max())
« no previous file with comments | « no previous file | base/time/time_unittest.cc » ('j') | base/time/time_unittest.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698