| 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.h" | 5 #include "base/time.h" |
| 6 | 6 |
| 7 #include <sys/time.h> | 7 #include <sys/time.h> |
| 8 #include <time.h> | 8 #include <time.h> |
| 9 #if defined(OS_ANDROID) | 9 #if defined(OS_ANDROID) |
| 10 #include <time64.h> | 10 #include <time64.h> |
| (...skipping 287 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 298 return Time(); | 298 return Time(); |
| 299 if (t.tv_usec == static_cast<suseconds_t>(Time::kMicrosecondsPerSecond) - 1 && | 299 if (t.tv_usec == static_cast<suseconds_t>(Time::kMicrosecondsPerSecond) - 1 && |
| 300 t.tv_sec == std::numeric_limits<time_t>::max()) | 300 t.tv_sec == std::numeric_limits<time_t>::max()) |
| 301 return Max(); | 301 return Max(); |
| 302 return Time( | 302 return Time( |
| 303 (static_cast<int64>(t.tv_sec) * Time::kMicrosecondsPerSecond) + | 303 (static_cast<int64>(t.tv_sec) * Time::kMicrosecondsPerSecond) + |
| 304 t.tv_usec + | 304 t.tv_usec + |
| 305 kTimeTToMicrosecondsOffset); | 305 kTimeTToMicrosecondsOffset); |
| 306 } | 306 } |
| 307 | 307 |
| 308 struct timeval Time::ToTimeVal() const { | 308 struct timespec Time::ToTimeSpec() const { |
| 309 struct timeval result; | 309 struct timespec result; |
| 310 if (is_null()) { | 310 if (is_null()) { |
| 311 result.tv_sec = 0; | 311 result.tv_sec = 0; |
| 312 result.tv_usec = 0; | 312 result.tv_nsec = 0; |
| 313 return result; | 313 return result; |
| 314 } | 314 } |
| 315 if (is_max()) { | 315 if (is_max()) { |
| 316 result.tv_sec = std::numeric_limits<time_t>::max(); | 316 result.tv_sec = std::numeric_limits<time_t>::max(); |
| 317 result.tv_usec = static_cast<suseconds_t>(Time::kMicrosecondsPerSecond) - 1; | 317 result.tv_nsec = static_cast<long>(Time::kNanosecondsPerSecond) - 1; |
| 318 return result; | 318 return result; |
| 319 } | 319 } |
| 320 int64 us = us_ - kTimeTToMicrosecondsOffset; | 320 int64 us = us_ - kTimeTToMicrosecondsOffset; |
| 321 result.tv_sec = us / Time::kMicrosecondsPerSecond; | 321 result.tv_sec = us / Time::kMicrosecondsPerSecond; |
| 322 result.tv_usec = us % Time::kMicrosecondsPerSecond; | 322 result.tv_nsec = (us % Time::kMicrosecondsPerSecond) * 1000; |
| 323 return result; | 323 return result; |
| 324 } | 324 } |
| 325 | 325 |
| 326 } // namespace base | 326 } // namespace base |
| OLD | NEW |