| OLD | NEW |
| 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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 | 9 |
| 10 #include <limits> | 10 #include <limits> |
| 11 | 11 |
| 12 #include "base/basictypes.h" | 12 #include "base/basictypes.h" |
| 13 #include "base/logging.h" | 13 #include "base/logging.h" |
| 14 | 14 |
| 15 namespace base { | 15 namespace base { |
| 16 | 16 |
| 17 #if !defined(OS_MACOSX) |
| 17 // The Time routines in this file use standard POSIX routines, or almost- | 18 // The Time routines in this file use standard POSIX routines, or almost- |
| 18 // standard routines in the case of timegm. We need to use a Mach-specific | 19 // standard routines in the case of timegm. We need to use a Mach-specific |
| 19 // function for TimeTicks::Now() on Mac OS X. | 20 // function for TimeTicks::Now() on Mac OS X. |
| 20 | 21 |
| 21 // Time ----------------------------------------------------------------------- | 22 // Time ----------------------------------------------------------------------- |
| 22 | 23 |
| 23 // Windows uses a Gregorian epoch of 1601. We need to match this internally | 24 // Windows uses a Gregorian epoch of 1601. We need to match this internally |
| 24 // so that our time representations match across all platforms. See bug 14734. | 25 // so that our time representations match across all platforms. See bug 14734. |
| 25 // irb(main):010:0> Time.at(0).getutc() | 26 // irb(main):010:0> Time.at(0).getutc() |
| 26 // => Thu Jan 01 00:00:00 UTC 1970 | 27 // => Thu Jan 01 00:00:00 UTC 1970 |
| (...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 167 | 168 |
| 168 #else // _POSIX_MONOTONIC_CLOCK | 169 #else // _POSIX_MONOTONIC_CLOCK |
| 169 #error No usable tick clock function on this platform. | 170 #error No usable tick clock function on this platform. |
| 170 #endif // _POSIX_MONOTONIC_CLOCK | 171 #endif // _POSIX_MONOTONIC_CLOCK |
| 171 | 172 |
| 172 // static | 173 // static |
| 173 TimeTicks TimeTicks::HighResNow() { | 174 TimeTicks TimeTicks::HighResNow() { |
| 174 return Now(); | 175 return Now(); |
| 175 } | 176 } |
| 176 | 177 |
| 178 #endif // !OS_MACOSX |
| 179 |
| 180 struct timespec TimeDelta::ToTimeSpec() const { |
| 181 int64 microseconds = InMicroseconds(); |
| 182 time_t seconds = 0; |
| 183 if (microseconds >= Time::kMicrosecondsPerSecond) { |
| 184 seconds = InSeconds(); |
| 185 microseconds -= seconds * Time::kMicrosecondsPerSecond; |
| 186 } |
| 187 struct timespec result = |
| 188 {seconds, |
| 189 microseconds * Time::kNanosecondsPerMicrosecond}; |
| 190 return result; |
| 191 } |
| 192 |
| 177 } // namespace base | 193 } // namespace base |
| OLD | NEW |