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

Side by Side 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « base/time_posix.cc ('k') | chrome/browser/bookmarks/bookmark_codec.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include <time.h> 5 #include <time.h>
6 6
7 #include "base/platform_thread.h" 7 #include "base/platform_thread.h"
8 #include "base/time.h" 8 #include "base/time.h"
9 #include "build/build_config.h" 9 #include "build/build_config.h"
10 #include "testing/gtest/include/gtest/gtest.h" 10 #include "testing/gtest/include/gtest/gtest.h"
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
59 EXPECT_EQ(0.0, zero_time.ToDoubleT()); 59 EXPECT_EQ(0.0, zero_time.ToDoubleT());
60 } 60 }
61 61
62 TEST(Time, LocalExplode) { 62 TEST(Time, LocalExplode) {
63 Time a = Time::Now(); 63 Time a = Time::Now();
64 Time::Exploded exploded; 64 Time::Exploded exploded;
65 a.LocalExplode(&exploded); 65 a.LocalExplode(&exploded);
66 66
67 Time b = Time::FromLocalExploded(exploded); 67 Time b = Time::FromLocalExploded(exploded);
68 68
69 // The exploded structure doesn't have microseconds, so the result will be 69 // The exploded structure doesn't have microseconds, and on Mac & Linux, the
70 // rounded to the nearest millisecond. 70 // internal OS conversion uses seconds, which will cause truncation. So we
71 EXPECT_TRUE((a - b) < TimeDelta::FromMilliseconds(1)); 71 // can only make sure that the delta is within one second.
72 EXPECT_TRUE((a - b) < TimeDelta::FromSeconds(1));
72 } 73 }
73 74
74 TEST(Time, UTCExplode) { 75 TEST(Time, UTCExplode) {
75 Time a = Time::Now(); 76 Time a = Time::Now();
76 Time::Exploded exploded; 77 Time::Exploded exploded;
77 a.UTCExplode(&exploded); 78 a.UTCExplode(&exploded);
78 79
79 Time b = Time::FromUTCExploded(exploded); 80 Time b = Time::FromUTCExploded(exploded);
80 EXPECT_TRUE((a - b) < TimeDelta::FromMilliseconds(1)); 81 EXPECT_TRUE((a - b) < TimeDelta::FromSeconds(1));
81 } 82 }
82 83
83 TEST(Time, LocalMidnight) { 84 TEST(Time, LocalMidnight) {
84 Time::Exploded exploded; 85 Time::Exploded exploded;
85 Time::Now().LocalMidnight().LocalExplode(&exploded); 86 Time::Now().LocalMidnight().LocalExplode(&exploded);
86 EXPECT_EQ(0, exploded.hour); 87 EXPECT_EQ(0, exploded.hour);
87 EXPECT_EQ(0, exploded.minute); 88 EXPECT_EQ(0, exploded.minute);
88 EXPECT_EQ(0, exploded.second); 89 EXPECT_EQ(0, exploded.second);
89 EXPECT_EQ(0, exploded.millisecond); 90 EXPECT_EQ(0, exploded.millisecond);
90 } 91 }
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
133 TimeDelta::FromMicroseconds(2000)); 134 TimeDelta::FromMicroseconds(2000));
134 EXPECT_EQ(13, TimeDelta::FromDays(13).InDays()); 135 EXPECT_EQ(13, TimeDelta::FromDays(13).InDays());
135 EXPECT_EQ(13, TimeDelta::FromHours(13).InHours()); 136 EXPECT_EQ(13, TimeDelta::FromHours(13).InHours());
136 EXPECT_EQ(13, TimeDelta::FromMinutes(13).InMinutes()); 137 EXPECT_EQ(13, TimeDelta::FromMinutes(13).InMinutes());
137 EXPECT_EQ(13, TimeDelta::FromSeconds(13).InSeconds()); 138 EXPECT_EQ(13, TimeDelta::FromSeconds(13).InSeconds());
138 EXPECT_EQ(13.0, TimeDelta::FromSeconds(13).InSecondsF()); 139 EXPECT_EQ(13.0, TimeDelta::FromSeconds(13).InSecondsF());
139 EXPECT_EQ(13, TimeDelta::FromMilliseconds(13).InMilliseconds()); 140 EXPECT_EQ(13, TimeDelta::FromMilliseconds(13).InMilliseconds());
140 EXPECT_EQ(13.0, TimeDelta::FromMilliseconds(13).InMillisecondsF()); 141 EXPECT_EQ(13.0, TimeDelta::FromMilliseconds(13).InMillisecondsF());
141 EXPECT_EQ(13, TimeDelta::FromMicroseconds(13).InMicroseconds()); 142 EXPECT_EQ(13, TimeDelta::FromMicroseconds(13).InMicroseconds());
142 } 143 }
144
145 // Our internal time format is serialized in things like databases, so it's
146 // important that it's consistent across all our platforms. We use the 1601
147 // Windows epoch as the internal format across all platforms.
148 TEST(TimeDelta, WindowsEpoch) {
149 Time::Exploded exploded;
150 exploded.year = 1970;
151 exploded.month = 1;
152 exploded.day_of_week = 0; // Should be unusued.
153 exploded.day_of_month = 1;
154 exploded.hour = 0;
155 exploded.minute = 0;
156 exploded.second = 0;
157 exploded.millisecond = 0;
158 Time t = Time::FromUTCExploded(exploded);
159 // Unix 1970 epoch.
160 EXPECT_EQ(GG_INT64_C(11644473600000000), t.ToInternalValue());
161
162 // We can't test 1601 epoch, since the system time functions on Linux
163 // only compute years starting from 1900.
164 }
OLDNEW
« 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