summaryrefslogtreecommitdiffstats
path: root/base/time_unittest.cc
diff options
context:
space:
mode:
authorbrettw@chromium.org <brettw@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-08-26 02:53:36 +0000
committerbrettw@chromium.org <brettw@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-08-26 02:53:36 +0000
commita4a3292e978cca3ad8c0baa5205054b5b3802e64 (patch)
tree9490d74f9760c4b841f1188e13b1a91db374c327 /base/time_unittest.cc
parent67d0d62d638f7b15e031dd2c22756df0109e021d (diff)
downloadchromium_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_unittest.cc')
-rw-r--r--base/time_unittest.cc30
1 files changed, 26 insertions, 4 deletions
diff --git a/base/time_unittest.cc b/base/time_unittest.cc
index ebe69eb..f8a62cb 100644
--- a/base/time_unittest.cc
+++ b/base/time_unittest.cc
@@ -66,9 +66,10 @@ TEST(Time, LocalExplode) {
Time b = Time::FromLocalExploded(exploded);
- // The exploded structure doesn't have microseconds, so the result will be
- // rounded to the nearest millisecond.
- EXPECT_TRUE((a - b) < TimeDelta::FromMilliseconds(1));
+ // The exploded structure doesn't have microseconds, and on Mac & Linux, the
+ // internal OS conversion uses seconds, which will cause truncation. So we
+ // can only make sure that the delta is within one second.
+ EXPECT_TRUE((a - b) < TimeDelta::FromSeconds(1));
}
TEST(Time, UTCExplode) {
@@ -77,7 +78,7 @@ TEST(Time, UTCExplode) {
a.UTCExplode(&exploded);
Time b = Time::FromUTCExploded(exploded);
- EXPECT_TRUE((a - b) < TimeDelta::FromMilliseconds(1));
+ EXPECT_TRUE((a - b) < TimeDelta::FromSeconds(1));
}
TEST(Time, LocalMidnight) {
@@ -140,3 +141,24 @@ TEST(TimeDelta, FromAndIn) {
EXPECT_EQ(13.0, TimeDelta::FromMilliseconds(13).InMillisecondsF());
EXPECT_EQ(13, TimeDelta::FromMicroseconds(13).InMicroseconds());
}
+
+// Our internal time format is serialized in things like databases, so it's
+// important that it's consistent across all our platforms. We use the 1601
+// Windows epoch as the internal format across all platforms.
+TEST(TimeDelta, WindowsEpoch) {
+ Time::Exploded exploded;
+ exploded.year = 1970;
+ exploded.month = 1;
+ exploded.day_of_week = 0; // Should be unusued.
+ exploded.day_of_month = 1;
+ exploded.hour = 0;
+ exploded.minute = 0;
+ exploded.second = 0;
+ exploded.millisecond = 0;
+ Time t = Time::FromUTCExploded(exploded);
+ // Unix 1970 epoch.
+ EXPECT_EQ(GG_INT64_C(11644473600000000), t.ToInternalValue());
+
+ // We can't test 1601 epoch, since the system time functions on Linux
+ // only compute years starting from 1900.
+}