| 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 <CoreFoundation/CFDate.h> | 7 #include <CoreFoundation/CFDate.h> |
| 8 #include <CoreFoundation/CFTimeZone.h> | 8 #include <CoreFoundation/CFTimeZone.h> |
| 9 #include <mach/mach.h> | 9 #include <mach/mach.h> |
| 10 #include <mach/mach_time.h> | 10 #include <mach/mach_time.h> |
| (...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 174 base::ScopedCFTypeRef<CFCalendarRef> gregorian(CFCalendarCreateWithIdentifier( | 174 base::ScopedCFTypeRef<CFCalendarRef> gregorian(CFCalendarCreateWithIdentifier( |
| 175 kCFAllocatorDefault, kCFGregorianCalendar)); | 175 kCFAllocatorDefault, kCFGregorianCalendar)); |
| 176 CFCalendarSetTimeZone(gregorian, time_zone); | 176 CFCalendarSetTimeZone(gregorian, time_zone); |
| 177 CFAbsoluteTime absolute_time; | 177 CFAbsoluteTime absolute_time; |
| 178 // 'S' is not defined in componentDesc in Apple documentation, but can be | 178 // 'S' is not defined in componentDesc in Apple documentation, but can be |
| 179 // found at http://www.opensource.apple.com/source/CF/CF-855.17/CFCalendar.c | 179 // found at http://www.opensource.apple.com/source/CF/CF-855.17/CFCalendar.c |
| 180 CFCalendarComposeAbsoluteTime( | 180 CFCalendarComposeAbsoluteTime( |
| 181 gregorian, &absolute_time, "yMdHmsS", exploded.year, exploded.month, | 181 gregorian, &absolute_time, "yMdHmsS", exploded.year, exploded.month, |
| 182 exploded.day_of_month, exploded.hour, exploded.minute, exploded.second, | 182 exploded.day_of_month, exploded.hour, exploded.minute, exploded.second, |
| 183 exploded.millisecond); | 183 exploded.millisecond); |
| 184 // Milliseconds from |exploded| is added back to |absolute_time| here | |
| 185 // because CFCalendar parameters are integer values. | |
| 186 CFAbsoluteTime seconds = absolute_time + kCFAbsoluteTimeIntervalSince1970; | 184 CFAbsoluteTime seconds = absolute_time + kCFAbsoluteTimeIntervalSince1970; |
| 187 return Time(static_cast<int64_t>(seconds * kMicrosecondsPerSecond) + | 185 return Time(static_cast<int64_t>(seconds * kMicrosecondsPerSecond) + |
| 188 kWindowsEpochDeltaMicroseconds); | 186 kWindowsEpochDeltaMicroseconds); |
| 189 } | 187 } |
| 190 | 188 |
| 191 void Time::Explode(bool is_local, Exploded* exploded) const { | 189 void Time::Explode(bool is_local, Exploded* exploded) const { |
| 192 // Avoid rounding issues, by only putting the integral number of seconds | 190 // Avoid rounding issues, by only putting the integral number of seconds |
| 193 // (rounded towards -infinity) into a |CFAbsoluteTime| (which is a |double|). | 191 // (rounded towards -infinity) into a |CFAbsoluteTime| (which is a |double|). |
| 194 int64_t microsecond = us_ % kMicrosecondsPerSecond; | 192 int64_t microsecond = us_ % kMicrosecondsPerSecond; |
| 195 if (microsecond < 0) | 193 if (microsecond < 0) |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 237 bool TimeTicks::IsHighResolution() { | 235 bool TimeTicks::IsHighResolution() { |
| 238 return true; | 236 return true; |
| 239 } | 237 } |
| 240 | 238 |
| 241 // static | 239 // static |
| 242 ThreadTicks ThreadTicks::Now() { | 240 ThreadTicks ThreadTicks::Now() { |
| 243 return ThreadTicks(ComputeThreadTicks()); | 241 return ThreadTicks(ComputeThreadTicks()); |
| 244 } | 242 } |
| 245 | 243 |
| 246 } // namespace base | 244 } // namespace base |
| OLD | NEW |