diff options
author | brettw@chromium.org <brettw@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-08-26 02:53:36 +0000 |
---|---|---|
committer | brettw@chromium.org <brettw@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-08-26 02:53:36 +0000 |
commit | a4a3292e978cca3ad8c0baa5205054b5b3802e64 (patch) | |
tree | 9490d74f9760c4b841f1188e13b1a91db374c327 /base/time_mac.cc | |
parent | 67d0d62d638f7b15e031dd2c22756df0109e021d (diff) | |
download | chromium_src-a4a3292e978cca3ad8c0baa5205054b5b3802e64.zip chromium_src-a4a3292e978cca3ad8c0baa5205054b5b3802e64.tar.gz chromium_src-a4a3292e978cca3ad8c0baa5205054b5b3802e64.tar.bz2 |
Convert internal time format to Windows 1601 epoch on Linux & Mac.
Although we represent time internally starting from 1601, there are still
things like time explosion that will not work before the year 1900. This
limitation is the same as it was previously.
BUG=14734
Review URL: http://codereview.chromium.org/173296
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@24417 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base/time_mac.cc')
-rw-r--r-- | base/time_mac.cc | 34 |
1 files changed, 24 insertions, 10 deletions
diff --git a/base/time_mac.cc b/base/time_mac.cc index 3e5e14a..6b46b95 100644 --- a/base/time_mac.cc +++ b/base/time_mac.cc @@ -24,20 +24,33 @@ 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. +// 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; -// 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. // static -const int64 Time::kTimeTToMicrosecondsOffset = GG_INT64_C(0); +const int64 Time::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 = 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 +74,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); |