| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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> |
| (...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 102 struct tm timestruct; | 102 struct tm timestruct; |
| 103 timestruct.tm_sec = exploded.second; | 103 timestruct.tm_sec = exploded.second; |
| 104 timestruct.tm_min = exploded.minute; | 104 timestruct.tm_min = exploded.minute; |
| 105 timestruct.tm_hour = exploded.hour; | 105 timestruct.tm_hour = exploded.hour; |
| 106 timestruct.tm_mday = exploded.day_of_month; | 106 timestruct.tm_mday = exploded.day_of_month; |
| 107 timestruct.tm_mon = exploded.month - 1; | 107 timestruct.tm_mon = exploded.month - 1; |
| 108 timestruct.tm_year = exploded.year - 1900; | 108 timestruct.tm_year = exploded.year - 1900; |
| 109 timestruct.tm_wday = exploded.day_of_week; // mktime/timegm ignore this | 109 timestruct.tm_wday = exploded.day_of_week; // mktime/timegm ignore this |
| 110 timestruct.tm_yday = 0; // mktime/timegm ignore this | 110 timestruct.tm_yday = 0; // mktime/timegm ignore this |
| 111 timestruct.tm_isdst = -1; // attempt to figure it out | 111 timestruct.tm_isdst = -1; // attempt to figure it out |
| 112 #if !defined(OS_NACL) |
| 112 timestruct.tm_gmtoff = 0; // not a POSIX field, so mktime/timegm ignore | 113 timestruct.tm_gmtoff = 0; // not a POSIX field, so mktime/timegm ignore |
| 113 timestruct.tm_zone = NULL; // not a POSIX field, so mktime/timegm ignore | 114 timestruct.tm_zone = NULL; // not a POSIX field, so mktime/timegm ignore |
| 115 #endif |
| 114 | 116 |
| 115 time_t seconds; | 117 time_t seconds; |
| 116 if (is_local) | 118 if (is_local) |
| 117 seconds = mktime(×truct); | 119 seconds = mktime(×truct); |
| 118 else | 120 else |
| 119 seconds = timegm(×truct); | 121 seconds = timegm(×truct); |
| 120 | 122 |
| 121 int64 milliseconds; | 123 int64 milliseconds; |
| 122 // Handle overflow. Clamping the range to what mktime and timegm might | 124 // Handle overflow. Clamping the range to what mktime and timegm might |
| 123 // return is the best that can be done here. It's not ideal, but it's better | 125 // return is the best that can be done here. It's not ideal, but it's better |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 172 return TimeTicks(); | 174 return TimeTicks(); |
| 173 } | 175 } |
| 174 | 176 |
| 175 absolute_micro = | 177 absolute_micro = |
| 176 (static_cast<int64>(ts.tv_sec) * Time::kMicrosecondsPerSecond) + | 178 (static_cast<int64>(ts.tv_sec) * Time::kMicrosecondsPerSecond) + |
| 177 (static_cast<int64>(ts.tv_nsec) / Time::kNanosecondsPerMicrosecond); | 179 (static_cast<int64>(ts.tv_nsec) / Time::kNanosecondsPerMicrosecond); |
| 178 | 180 |
| 179 return TimeTicks(absolute_micro); | 181 return TimeTicks(absolute_micro); |
| 180 } | 182 } |
| 181 | 183 |
| 184 #elif defined(OS_NACL) |
| 185 |
| 186 TimeTicks TimeTicks::Now() { |
| 187 // Sadly, Native Client does not have _POSIX_TIMERS enabled in sys/features.h |
| 188 // Apparently NaCl only has CLOCK_REALTIME: |
| 189 // http://code.google.com/p/nativeclient/issues/detail?id=1159 |
| 190 return TimeTicks(clock()); |
| 191 } |
| 192 |
| 182 #else // _POSIX_MONOTONIC_CLOCK | 193 #else // _POSIX_MONOTONIC_CLOCK |
| 183 #error No usable tick clock function on this platform. | 194 #error No usable tick clock function on this platform. |
| 184 #endif // _POSIX_MONOTONIC_CLOCK | 195 #endif // _POSIX_MONOTONIC_CLOCK |
| 185 | 196 |
| 186 // static | 197 // static |
| 187 TimeTicks TimeTicks::HighResNow() { | 198 TimeTicks TimeTicks::HighResNow() { |
| 188 return Now(); | 199 return Now(); |
| 189 } | 200 } |
| 190 | 201 |
| 191 #endif // !OS_MACOSX | 202 #endif // !OS_MACOSX |
| 192 | 203 |
| 193 struct timeval Time::ToTimeVal() const { | 204 struct timeval Time::ToTimeVal() const { |
| 194 struct timeval result; | 205 struct timeval result; |
| 195 int64 us = us_ - kTimeTToMicrosecondsOffset; | 206 int64 us = us_ - kTimeTToMicrosecondsOffset; |
| 196 result.tv_sec = us / Time::kMicrosecondsPerSecond; | 207 result.tv_sec = us / Time::kMicrosecondsPerSecond; |
| 197 result.tv_usec = us % Time::kMicrosecondsPerSecond; | 208 result.tv_usec = us % Time::kMicrosecondsPerSecond; |
| 198 return result; | 209 return result; |
| 199 } | 210 } |
| 200 | 211 |
| 201 } // namespace base | 212 } // namespace base |
| OLD | NEW |