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

Side by Side 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: Added helper method to time Created 7 years, 4 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 unified diff | Download patch
« no previous file with comments | « base/time/time.h ('k') | chrome/browser/android/foreign_session_helper.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "base/time/time.h" 5 #include "base/time/time.h"
6 6
7 #include <math.h> 7 #include <math.h>
8 #include <limits> 8 #include <limits>
9 9
10 #include "base/float_util.h" 10 #include "base/float_util.h"
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after
131 return 0; 131 return 0;
132 } 132 }
133 if (is_max()) { 133 if (is_max()) {
134 // Preserve max without offset to prevent overflow. 134 // Preserve max without offset to prevent overflow.
135 return std::numeric_limits<double>::max(); 135 return std::numeric_limits<double>::max();
136 } 136 }
137 return (static_cast<double>(us_ - kTimeTToMicrosecondsOffset) / 137 return (static_cast<double>(us_ - kTimeTToMicrosecondsOffset) /
138 kMicrosecondsPerMillisecond); 138 kMicrosecondsPerMillisecond);
139 } 139 }
140 140
141 int64 Time::ToJavaTime() const {
Mark Mentovai 2013/09/20 15:46:25 It looks like, given this and ToJsTime’s equivalen
apiccion 2013/09/20 18:21:48 Thank you! On 2013/09/20 15:46:25, Mark Mentovai
142 if (is_null()) {
143 return 0;
Mark Mentovai 2013/09/20 15:46:25 You seem to have copied this from ToJsTime, but yo
apiccion 2013/09/20 18:21:48 Done.
144 }
145 if (is_max()) {
146 // Preserve max without offset to prevent overflow.
147 return std::numeric_limits<long>::max();
Mark Mentovai 2013/09/20 15:46:25 long is the wrong type here.
apiccion 2013/09/20 18:21:48 Done.
148 }
149 return ((us_ - kTimeTToMicrosecondsOffset) /
150 kMicrosecondsPerMillisecond);
151 }
152
141 // static 153 // static
142 Time Time::UnixEpoch() { 154 Time Time::UnixEpoch() {
143 Time time; 155 Time time;
144 time.us_ = kTimeTToMicrosecondsOffset; 156 time.us_ = kTimeTToMicrosecondsOffset;
145 return time; 157 return time;
146 } 158 }
147 159
148 Time Time::LocalMidnight() const { 160 Time Time::LocalMidnight() const {
149 Exploded exploded; 161 Exploded exploded;
150 LocalExplode(&exploded); 162 LocalExplode(&exploded);
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
186 return is_in_range(month, 1, 12) && 198 return is_in_range(month, 1, 12) &&
187 is_in_range(day_of_week, 0, 6) && 199 is_in_range(day_of_week, 0, 6) &&
188 is_in_range(day_of_month, 1, 31) && 200 is_in_range(day_of_month, 1, 31) &&
189 is_in_range(hour, 0, 23) && 201 is_in_range(hour, 0, 23) &&
190 is_in_range(minute, 0, 59) && 202 is_in_range(minute, 0, 59) &&
191 is_in_range(second, 0, 60) && 203 is_in_range(second, 0, 60) &&
192 is_in_range(millisecond, 0, 999); 204 is_in_range(millisecond, 0, 999);
193 } 205 }
194 206
195 } // namespace base 207 } // namespace base
OLDNEW
« no previous file with comments | « base/time/time.h ('k') | chrome/browser/android/foreign_session_helper.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698