Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(158)

Side by Side Diff: base/time_mac.cc

Issue 4471001: Reland http://codereview.chromium.org/4139008, with a different (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: this crap still does not work Created 10 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | base/time_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2008 The Chromium Authors. All rights reserved. 1 // Copyright (c) 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 <CoreFoundation/CFDate.h> 7 #include <CoreFoundation/CFDate.h>
8 #include <CoreFoundation/CFTimeZone.h> 8 #include <CoreFoundation/CFTimeZone.h>
9 #include <mach/mach_time.h> 9 #include <mach/mach_time.h>
10 #include <sys/time.h> 10 #include <sys/time.h>
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
55 55
56 // static 56 // static
57 Time Time::NowFromSystemTime() { 57 Time Time::NowFromSystemTime() {
58 // Just use Now() because Now() returns the system time. 58 // Just use Now() because Now() returns the system time.
59 return Now(); 59 return Now();
60 } 60 }
61 61
62 // static 62 // static
63 Time Time::FromExploded(bool is_local, const Exploded& exploded) { 63 Time Time::FromExploded(bool is_local, const Exploded& exploded) {
64 CFGregorianDate date; 64 CFGregorianDate date;
65 date.second = exploded.second + 65 date.second = exploded.second;
66 exploded.millisecond / static_cast<double>(kMillisecondsPerSecond);
67 date.minute = exploded.minute; 66 date.minute = exploded.minute;
68 date.hour = exploded.hour; 67 date.hour = exploded.hour;
69 date.day = exploded.day_of_month; 68 date.day = exploded.day_of_month;
70 date.month = exploded.month; 69 date.month = exploded.month;
71 date.year = exploded.year; 70 date.year = exploded.year;
72 71
73 base::mac::ScopedCFTypeRef<CFTimeZoneRef> 72 base::mac::ScopedCFTypeRef<CFTimeZoneRef>
74 time_zone(is_local ? CFTimeZoneCopySystem() : NULL); 73 time_zone(is_local ? CFTimeZoneCopySystem() : NULL);
75 CFAbsoluteTime seconds = CFGregorianDateGetAbsoluteTime(date, time_zone) + 74 CFAbsoluteTime seconds = CFGregorianDateGetAbsoluteTime(date, time_zone) +
76 kCFAbsoluteTimeIntervalSince1970; 75 kCFAbsoluteTimeIntervalSince1970;
77 return Time(static_cast<int64>(seconds * kMicrosecondsPerSecond) + 76 Time result(static_cast<int64>(seconds * kMicrosecondsPerSecond) +
78 kWindowsEpochDeltaMicroseconds); 77 kWindowsEpochDeltaMicroseconds);
78
79 // Need to add milliseconds in at the end because
80 // CFGregorianDateGetAbsoluteTime deals only in second resolution.
81 result += TimeDelta::FromMilliseconds(exploded.millisecond);
82 return result;
79 } 83 }
80 84
81 void Time::Explode(bool is_local, Exploded* exploded) const { 85 void Time::Explode(bool is_local, Exploded* exploded) const {
82 CFAbsoluteTime seconds = 86 double seconds =
83 (static_cast<double>((us_ - kWindowsEpochDeltaMicroseconds) / 87 (static_cast<double>((us_ - kWindowsEpochDeltaMicroseconds) /
84 kMicrosecondsPerSecond) - kCFAbsoluteTimeIntervalSince1970); 88 kMicrosecondsPerSecond) - kCFAbsoluteTimeIntervalSince1970);
85 89
86 base::mac::ScopedCFTypeRef<CFTimeZoneRef> 90 base::mac::ScopedCFTypeRef<CFTimeZoneRef>
87 time_zone(is_local ? CFTimeZoneCopySystem() : NULL); 91 time_zone(is_local ? CFTimeZoneCopySystem() : NULL);
88 CFGregorianDate date = CFAbsoluteTimeGetGregorianDate(seconds, time_zone); 92 CFGregorianDate date = CFAbsoluteTimeGetGregorianDate(
93 static_cast<CFAbsoluteTime>(seconds), time_zone);
89 94
90 exploded->year = date.year; 95 exploded->year = date.year;
91 exploded->month = date.month; 96 exploded->month = date.month;
92 exploded->day_of_month = date.day; 97 exploded->day_of_month = date.day;
93 exploded->hour = date.hour; 98 exploded->hour = date.hour;
94 exploded->minute = date.minute; 99 exploded->minute = date.minute;
95 exploded->second = date.second; 100 exploded->second = date.second;
96 exploded->millisecond = 101 exploded->millisecond = static_cast<int>(
97 static_cast<int>(date.second * kMillisecondsPerSecond) % 102 static_cast<int64>(seconds * kMillisecondsPerSecond) % kMillisecondsPerSec ond);
98 kMillisecondsPerSecond;
99 } 103 }
100 104
101 // TimeTicks ------------------------------------------------------------------ 105 // TimeTicks ------------------------------------------------------------------
102 106
103 // static 107 // static
104 TimeTicks TimeTicks::Now() { 108 TimeTicks TimeTicks::Now() {
105 uint64_t absolute_micro; 109 uint64_t absolute_micro;
106 110
107 static mach_timebase_info_data_t timebase_info; 111 static mach_timebase_info_data_t timebase_info;
108 if (timebase_info.denom == 0) { 112 if (timebase_info.denom == 0) {
(...skipping 21 matching lines...) Expand all
130 134
131 return TimeTicks(absolute_micro); 135 return TimeTicks(absolute_micro);
132 } 136 }
133 137
134 // static 138 // static
135 TimeTicks TimeTicks::HighResNow() { 139 TimeTicks TimeTicks::HighResNow() {
136 return Now(); 140 return Now();
137 } 141 }
138 142
139 } // namespace base 143 } // namespace base
OLDNEW
« no previous file with comments | « no previous file | base/time_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698