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

Unified 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | base/time_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/time_mac.cc
diff --git a/base/time_mac.cc b/base/time_mac.cc
index 6dfaa20e00fdc964bac80e6f915671b924b5b89b..e9781a611f8cfd7fa41767a6a5782e07a65c22ff 100644
--- a/base/time_mac.cc
+++ b/base/time_mac.cc
@@ -62,8 +62,7 @@ Time Time::NowFromSystemTime() {
// static
Time Time::FromExploded(bool is_local, const Exploded& exploded) {
CFGregorianDate date;
- date.second = exploded.second +
- exploded.millisecond / static_cast<double>(kMillisecondsPerSecond);
+ date.second = exploded.second;
date.minute = exploded.minute;
date.hour = exploded.hour;
date.day = exploded.day_of_month;
@@ -74,18 +73,24 @@ Time Time::FromExploded(bool is_local, const Exploded& exploded) {
time_zone(is_local ? CFTimeZoneCopySystem() : NULL);
CFAbsoluteTime seconds = CFGregorianDateGetAbsoluteTime(date, time_zone) +
kCFAbsoluteTimeIntervalSince1970;
- return Time(static_cast<int64>(seconds * kMicrosecondsPerSecond) +
+ Time result(static_cast<int64>(seconds * kMicrosecondsPerSecond) +
kWindowsEpochDeltaMicroseconds);
+
+ // Need to add milliseconds in at the end because
+ // CFGregorianDateGetAbsoluteTime deals only in second resolution.
+ result += TimeDelta::FromMilliseconds(exploded.millisecond);
+ return result;
}
void Time::Explode(bool is_local, Exploded* exploded) const {
- CFAbsoluteTime seconds =
+ double seconds =
(static_cast<double>((us_ - kWindowsEpochDeltaMicroseconds) /
kMicrosecondsPerSecond) - kCFAbsoluteTimeIntervalSince1970);
base::mac::ScopedCFTypeRef<CFTimeZoneRef>
time_zone(is_local ? CFTimeZoneCopySystem() : NULL);
- CFGregorianDate date = CFAbsoluteTimeGetGregorianDate(seconds, time_zone);
+ CFGregorianDate date = CFAbsoluteTimeGetGregorianDate(
+ static_cast<CFAbsoluteTime>(seconds), time_zone);
exploded->year = date.year;
exploded->month = date.month;
@@ -93,9 +98,8 @@ void Time::Explode(bool is_local, Exploded* exploded) const {
exploded->hour = date.hour;
exploded->minute = date.minute;
exploded->second = date.second;
- exploded->millisecond =
- static_cast<int>(date.second * kMillisecondsPerSecond) %
- kMillisecondsPerSecond;
+ exploded->millisecond = static_cast<int>(
+ static_cast<int64>(seconds * kMillisecondsPerSecond) % kMillisecondsPerSecond);
}
// TimeTicks ------------------------------------------------------------------
« 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