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