| 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 #include <unistd.h> | 9 #include <unistd.h> | 
| 10 | 10 | 
| (...skipping 248 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 259 } | 259 } | 
| 260 | 260 | 
| 261 #endif // defined(OS_CHROMEOS) | 261 #endif // defined(OS_CHROMEOS) | 
| 262 | 262 | 
| 263 #endif  // !OS_MACOSX | 263 #endif  // !OS_MACOSX | 
| 264 | 264 | 
| 265 // static | 265 // static | 
| 266 Time Time::FromTimeVal(struct timeval t) { | 266 Time Time::FromTimeVal(struct timeval t) { | 
| 267   DCHECK_LT(t.tv_usec, static_cast<int>(Time::kMicrosecondsPerSecond)); | 267   DCHECK_LT(t.tv_usec, static_cast<int>(Time::kMicrosecondsPerSecond)); | 
| 268   DCHECK_GE(t.tv_usec, 0); | 268   DCHECK_GE(t.tv_usec, 0); | 
|  | 269   if (t.tv_usec == 0 && t.tv_sec == 0) | 
|  | 270     return Time(); | 
|  | 271   if (t.tv_usec == static_cast<suseconds_t>(Time::kMicrosecondsPerSecond) - 1 && | 
|  | 272       t.tv_sec == std::numeric_limits<time_t>::max()) | 
|  | 273     return Max(); | 
| 269   return Time( | 274   return Time( | 
| 270       (static_cast<int64>(t.tv_sec) * Time::kMicrosecondsPerSecond) + | 275       (static_cast<int64>(t.tv_sec) * Time::kMicrosecondsPerSecond) + | 
| 271       t.tv_usec + | 276       t.tv_usec + | 
| 272       kTimeTToMicrosecondsOffset); | 277       kTimeTToMicrosecondsOffset); | 
| 273 } | 278 } | 
| 274 | 279 | 
| 275 struct timeval Time::ToTimeVal() const { | 280 struct timeval Time::ToTimeVal() const { | 
| 276   struct timeval result; | 281   struct timeval result; | 
|  | 282   if (is_null()) { | 
|  | 283     result.tv_sec = 0; | 
|  | 284     result.tv_usec = 0; | 
|  | 285     return result; | 
|  | 286   } | 
|  | 287   if (is_max()) { | 
|  | 288     result.tv_sec = std::numeric_limits<time_t>::max(); | 
|  | 289     result.tv_usec = static_cast<suseconds_t>(Time::kMicrosecondsPerSecond) - 1; | 
|  | 290     return result; | 
|  | 291   } | 
| 277   int64 us = us_ - kTimeTToMicrosecondsOffset; | 292   int64 us = us_ - kTimeTToMicrosecondsOffset; | 
| 278   result.tv_sec = us / Time::kMicrosecondsPerSecond; | 293   result.tv_sec = us / Time::kMicrosecondsPerSecond; | 
| 279   result.tv_usec = us % Time::kMicrosecondsPerSecond; | 294   result.tv_usec = us % Time::kMicrosecondsPerSecond; | 
| 280   return result; | 295   return result; | 
| 281 } | 296 } | 
| 282 | 297 | 
| 283 }  // namespace base | 298 }  // namespace base | 
| OLD | NEW | 
|---|