diff options
author | apiccion@chromium.org <apiccion@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-09-23 17:52:36 +0000 |
---|---|---|
committer | apiccion@chromium.org <apiccion@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-09-23 17:52:36 +0000 |
commit | 332c08e51f1799258d210e64c211debc18cf6c6a (patch) | |
tree | 7167c8ea764a0a197814dca49beea94b576cba63 /base | |
parent | 89d4df2b13c95ff1545320f5763c7b6eac0aa962 (diff) | |
download | chromium_src-332c08e51f1799258d210e64c211debc18cf6c6a.zip chromium_src-332c08e51f1799258d210e64c211debc18cf6c6a.tar.gz chromium_src-332c08e51f1799258d210e64c211debc18cf6c6a.tar.bz2 |
Added method to convert base::Time to a Java timestamp.
BUG=247382
Review URL: https://chromiumcodereview.appspot.com/22791013
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@224744 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base')
-rw-r--r-- | base/time/time.cc | 13 | ||||
-rw-r--r-- | base/time/time.h | 4 |
2 files changed, 17 insertions, 0 deletions
diff --git a/base/time/time.cc b/base/time/time.cc index ce25dea..a9e4b1c 100644 --- a/base/time/time.cc +++ b/base/time/time.cc @@ -138,6 +138,19 @@ double Time::ToJsTime() const { kMicrosecondsPerMillisecond); } +int64 Time::ToJavaTime() const { + if (is_null()) { + // Preserve 0 so the invalid result doesn't depend on the platform. + return 0; + } + if (is_max()) { + // Preserve max without offset to prevent overflow. + return std::numeric_limits<int64>::max(); + } + return ((us_ - kTimeTToMicrosecondsOffset) / + kMicrosecondsPerMillisecond); +} + // static Time Time::UnixEpoch() { Time time; diff --git a/base/time/time.h b/base/time/time.h index 5d7033a..a236a3f 100644 --- a/base/time/time.h +++ b/base/time/time.h @@ -300,6 +300,10 @@ class BASE_EXPORT Time { static Time FromJsTime(double ms_since_epoch); double ToJsTime() const; + // Converts to Java convention for times, a number of + // milliseconds since the epoch. + int64 ToJavaTime() const; + #if defined(OS_POSIX) static Time FromTimeVal(struct timeval t); struct timeval ToTimeVal() const; |