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

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: ' 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 unified diff | Download patch
« no previous file with comments | « base/time/time.h ('k') | no next file » | 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 <limits> 7 #include <limits>
8 #include <ostream> 8 #include <ostream>
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 {
142 if (is_null()) {
143 // Preserve 0 so the invalid result doesn't depend on the platform.
144 return 0;
145 }
146 if (is_max()) {
147 // Preserve max without offset to prevent overflow.
148 return std::numeric_limits<int64>::max();
149 }
150 return ((us_ - kTimeTToMicrosecondsOffset) /
151 kMicrosecondsPerMillisecond);
152 }
153
141 // static 154 // static
142 Time Time::UnixEpoch() { 155 Time Time::UnixEpoch() {
143 Time time; 156 Time time;
144 time.us_ = kTimeTToMicrosecondsOffset; 157 time.us_ = kTimeTToMicrosecondsOffset;
145 return time; 158 return time;
146 } 159 }
147 160
148 Time Time::LocalMidnight() const { 161 Time Time::LocalMidnight() const {
149 Exploded exploded; 162 Exploded exploded;
150 LocalExplode(&exploded); 163 LocalExplode(&exploded);
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
186 return is_in_range(month, 1, 12) && 199 return is_in_range(month, 1, 12) &&
187 is_in_range(day_of_week, 0, 6) && 200 is_in_range(day_of_week, 0, 6) &&
188 is_in_range(day_of_month, 1, 31) && 201 is_in_range(day_of_month, 1, 31) &&
189 is_in_range(hour, 0, 23) && 202 is_in_range(hour, 0, 23) &&
190 is_in_range(minute, 0, 59) && 203 is_in_range(minute, 0, 59) &&
191 is_in_range(second, 0, 60) && 204 is_in_range(second, 0, 60) &&
192 is_in_range(millisecond, 0, 999); 205 is_in_range(millisecond, 0, 999);
193 } 206 }
194 207
195 } // namespace base 208 } // namespace base
OLDNEW
« 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