OLD | NEW |
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 Loading... |
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 Loading... |
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 |
OLD | NEW |