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

Unified Diff: base/time/time.cc

Issue 22791013: Method to convet base::Time to Java timestamp. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: ' Created 7 years, 3 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/time.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/time/time.cc
diff --git a/base/time/time.cc b/base/time/time.cc
index ce25dea0589dfae7ad5b55ffd98a95a33fa7704a..a9e4b1cf90aa61c031feaa05f52a01111090f431 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;
« no previous file with comments | « base/time/time.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698