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

Unified Diff: base/time.cc

Issue 10536061: Add Javascript time methods to base::Time. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 6 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.h ('k') | base/time_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/time.cc
diff --git a/base/time.cc b/base/time.cc
index 859810e7cfe36b8f894a638803ef2b7a315ae086..031409ea918f052548f1218c9b1d5006bc161a27 100644
--- a/base/time.cc
+++ b/base/time.cc
@@ -81,6 +81,23 @@ double Time::ToDoubleT() const {
}
// static
+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(static_cast<int64>(ms_since_epoch * kMicrosecondsPerMillisecond) +
+ kTimeTToMicrosecondsOffset);
+}
+
+double Time::ToJsTime() const {
+ if (us_ == 0) {
Jeffrey Yasskin 2012/06/08 19:20:16 It may actually make sense to CHECK(!is_null()) he
+ // Preserve 0 so the invalid result doesn't depend on the platform.
+ return 0;
+ }
+ return (static_cast<double>(us_ - kTimeTToMicrosecondsOffset) /
+ kMicrosecondsPerMillisecond);
+}
+
+// static
Time Time::UnixEpoch() {
Time time;
time.us_ = kTimeTToMicrosecondsOffset;
« no previous file with comments | « base/time.h ('k') | base/time_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698