summaryrefslogtreecommitdiffstats
path: root/base/time.cc
diff options
context:
space:
mode:
authorjyasskin@chromium.org <jyasskin@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-06-08 22:59:33 +0000
committerjyasskin@chromium.org <jyasskin@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-06-08 22:59:33 +0000
commit42132be3f9f8aadc2de3f8c29ece41e19a4f6281 (patch)
tree3ace4954e2aff3d7dd7336d30e5c77a69c6833c8 /base/time.cc
parentdcb797daf4fec6ec78d6536d4c946e8179d4edc7 (diff)
downloadchromium_src-42132be3f9f8aadc2de3f8c29ece41e19a4f6281.zip
chromium_src-42132be3f9f8aadc2de3f8c29ece41e19a4f6281.tar.gz
chromium_src-42132be3f9f8aadc2de3f8c29ece41e19a4f6281.tar.bz2
Add Javascript time methods to base::Time.
Review URL: https://chromiumcodereview.appspot.com/10536061 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@141317 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base/time.cc')
-rw-r--r--base/time.cc17
1 files changed, 17 insertions, 0 deletions
diff --git a/base/time.cc b/base/time.cc
index 39a8b56..f04ebbc 100644
--- a/base/time.cc
+++ b/base/time.cc
@@ -93,6 +93,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) {
+ // 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;