| 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 <cmath> | 7 #include <cmath> |
| 8 #include <ios> | 8 #include <ios> |
| 9 #include <limits> | 9 #include <limits> |
| 10 #include <ostream> | 10 #include <ostream> |
| (...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 196 return 0; | 196 return 0; |
| 197 } | 197 } |
| 198 if (is_max()) { | 198 if (is_max()) { |
| 199 // Preserve max without offset to prevent overflow. | 199 // Preserve max without offset to prevent overflow. |
| 200 return std::numeric_limits<double>::infinity(); | 200 return std::numeric_limits<double>::infinity(); |
| 201 } | 201 } |
| 202 return (static_cast<double>(us_ - kTimeTToMicrosecondsOffset) / | 202 return (static_cast<double>(us_ - kTimeTToMicrosecondsOffset) / |
| 203 kMicrosecondsPerMillisecond); | 203 kMicrosecondsPerMillisecond); |
| 204 } | 204 } |
| 205 | 205 |
| 206 Time Time::FromJavaTime(int64_t ms_since_epoch) { |
| 207 return base::Time::UnixEpoch() + |
| 208 base::TimeDelta::FromMilliseconds(ms_since_epoch); |
| 209 } |
| 210 |
| 206 int64_t Time::ToJavaTime() const { | 211 int64_t Time::ToJavaTime() const { |
| 207 if (is_null()) { | 212 if (is_null()) { |
| 208 // Preserve 0 so the invalid result doesn't depend on the platform. | 213 // Preserve 0 so the invalid result doesn't depend on the platform. |
| 209 return 0; | 214 return 0; |
| 210 } | 215 } |
| 211 if (is_max()) { | 216 if (is_max()) { |
| 212 // Preserve max without offset to prevent overflow. | 217 // Preserve max without offset to prevent overflow. |
| 213 return std::numeric_limits<int64_t>::max(); | 218 return std::numeric_limits<int64_t>::max(); |
| 214 } | 219 } |
| 215 return ((us_ - kTimeTToMicrosecondsOffset) / | 220 return ((us_ - kTimeTToMicrosecondsOffset) / |
| (...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 337 return is_in_range(month, 1, 12) && | 342 return is_in_range(month, 1, 12) && |
| 338 is_in_range(day_of_week, 0, 6) && | 343 is_in_range(day_of_week, 0, 6) && |
| 339 is_in_range(day_of_month, 1, 31) && | 344 is_in_range(day_of_month, 1, 31) && |
| 340 is_in_range(hour, 0, 23) && | 345 is_in_range(hour, 0, 23) && |
| 341 is_in_range(minute, 0, 59) && | 346 is_in_range(minute, 0, 59) && |
| 342 is_in_range(second, 0, 60) && | 347 is_in_range(second, 0, 60) && |
| 343 is_in_range(millisecond, 0, 999); | 348 is_in_range(millisecond, 0, 999); |
| 344 } | 349 } |
| 345 | 350 |
| 346 } // namespace base | 351 } // namespace base |
| OLD | NEW |