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

Unified Diff: base/time_mac.cc

Issue 150097: Convert Linux internal time format to Windows 1601 epoch. (Closed)
Patch Set: Apply mac patch Created 11 years, 5 months 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_posix.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 3e5e14a00c5bf83acdf8553a4342505ccb68ba62..8d58225f6cf0a37144f583861037ccb24e4de7bc 100644
--- a/base/time_mac.cc
+++ b/base/time_mac.cc
@@ -24,20 +24,31 @@ namespace base {
// Time -----------------------------------------------------------------------
-// The internal representation of Time uses a 64-bit microsecond count
-// from 1970-01-01 00:00:00 UTC. Core Foundation uses a double second count
-// since 2001-01-01 00:00:00 UTC.
-
-// Some functions in time.cc use time_t directly, so we provide a zero offset
-// for them. The epoch is 1970-01-01 00:00:00 UTC.
+// Core Foundation uses a double second count since 2001-01-01 00:00:00 UTC.
+// The UNIX epoch is 1970-01-01 00:00:00 UTC.
+// Windows uses a Gregorian epoch of 1601. We need to match this internally
+// so that our time representations match across all platforms. See bug 14734.
+// irb(main):010:0> Time.at(0).getutc()
+// => Thu Jan 01 00:00:00 UTC 1970
+// irb(main):011:0> Time.at(-11644473600).getutc()
+// => Mon Jan 01 00:00:00 UTC 1601
+static const int64 kWindowsEpochDeltaSeconds = GG_INT64_C(11644473600);
+static const int64 kWindowsEpochDeltaMilliseconds =
+ kWindowsEpochDeltaSeconds * Time::kMillisecondsPerSecond;
+static const int64 kWindowsEpochDeltaMicroseconds =
+ kWindowsEpochDeltaSeconds * Time::kMicrosecondsPerSecond;
+
+// Some functions in time.cc use time_t directly, so we provide an offset
+// to convert from time_t (Unix epoch) and internal (Windows epoch).
// static
-const int64 Time::kTimeTToMicrosecondsOffset = GG_INT64_C(0);
-
+const int64 Time::kTimeTToMicrosecondsOffset = kWindowsEpochDeltaMicroseconds;
+
// static
Time Time::Now() {
CFAbsoluteTime now =
CFAbsoluteTimeGetCurrent() + kCFAbsoluteTimeIntervalSince1970;
- return Time(static_cast<int64>(now * kMicrosecondsPerSecond));
+ return Time(static_cast<int64>(now * kMicrosecondsPerSecond) +
+ kWindowsEpochDeltaMicroseconds);
}
// static
@@ -61,13 +72,14 @@ 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));
+ return Time(static_cast<int64>(seconds * kMicrosecondsPerSecond) +
+ kWindowsEpochDeltaMicroseconds);
}
void Time::Explode(bool is_local, Exploded* exploded) const {
CFAbsoluteTime seconds =
- (static_cast<double>(us_) / kMicrosecondsPerSecond) -
- kCFAbsoluteTimeIntervalSince1970;
+ (static_cast<double>((us_ - kWindowsEpochDeltaMicroseconds) /
+ kMicrosecondsPerSecond) - kCFAbsoluteTimeIntervalSince1970);
scoped_cftyperef<CFTimeZoneRef>
time_zone(is_local ? CFTimeZoneCopySystem() : NULL);
« no previous file with comments | « no previous file | base/time_posix.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698