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; |