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

Unified Diff: base/time_unittest.cc

Issue 173296: Convert internal time format to Windows 1601 epoch on Linux & Mac.... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 11 years, 4 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 | « base/time_posix.cc ('k') | chrome/browser/bookmarks/bookmark_codec.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/time_unittest.cc
===================================================================
--- base/time_unittest.cc (revision 24094)
+++ base/time_unittest.cc (working copy)
@@ -66,9 +66,10 @@
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 @@
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 @@
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.
+}
« no previous file with comments | « base/time_posix.cc ('k') | chrome/browser/bookmarks/bookmark_codec.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698