| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "base/time/time.h" | 5 #include "base/time/time.h" |
| 6 | 6 |
| 7 #include <stdint.h> | 7 #include <stdint.h> |
| 8 #include <time.h> | 8 #include <time.h> |
| 9 #include <limits> | 9 #include <limits> |
| 10 #include <string> | 10 #include <string> |
| (...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 152 } | 152 } |
| 153 | 153 |
| 154 // Test conversions to/from javascript time. | 154 // Test conversions to/from javascript time. |
| 155 TEST_F(TimeTest, JsTime) { | 155 TEST_F(TimeTest, JsTime) { |
| 156 Time epoch = Time::FromJsTime(0.0); | 156 Time epoch = Time::FromJsTime(0.0); |
| 157 EXPECT_EQ(epoch, Time::UnixEpoch()); | 157 EXPECT_EQ(epoch, Time::UnixEpoch()); |
| 158 Time t = Time::FromJsTime(700000.3); | 158 Time t = Time::FromJsTime(700000.3); |
| 159 EXPECT_EQ(700.0003, t.ToDoubleT()); | 159 EXPECT_EQ(700.0003, t.ToDoubleT()); |
| 160 t = Time::FromDoubleT(800.73); | 160 t = Time::FromDoubleT(800.73); |
| 161 EXPECT_EQ(800730.0, t.ToJsTime()); | 161 EXPECT_EQ(800730.0, t.ToJsTime()); |
| 162 |
| 163 // Correctly convert |- epoch offset| which is valid time in javascript. |
| 164 Time minusEpoch = Time::FromJsTime(-11644473600000.0); |
| 165 EXPECT_EQ(-11644473600000, minusEpoch.ToJsTime()); |
| 166 |
| 167 // Check conversion of boundary javascript time values. |
| 168 // See http://www.ecma-international.org/ecma-262/6.0/#sec-timeclip |
| 169 EXPECT_EQ(-8.46e15, Time::FromJsTime(-8.46e15).ToJsTime()); |
| 170 EXPECT_EQ(8.46e15, Time::FromJsTime(8.46e15).ToJsTime()); |
| 162 } | 171 } |
| 163 | 172 |
| 164 #if defined(OS_POSIX) | 173 #if defined(OS_POSIX) |
| 165 TEST_F(TimeTest, FromTimeVal) { | 174 TEST_F(TimeTest, FromTimeVal) { |
| 166 Time now = Time::Now(); | 175 Time now = Time::Now(); |
| 167 Time also_now = Time::FromTimeVal(now.ToTimeVal()); | 176 Time also_now = Time::FromTimeVal(now.ToTimeVal()); |
| 168 EXPECT_EQ(now, also_now); | 177 EXPECT_EQ(now, also_now); |
| 169 } | 178 } |
| 170 #endif // OS_POSIX | 179 #endif // OS_POSIX |
| 171 | 180 |
| (...skipping 1018 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1190 | 1199 |
| 1191 TEST(TimeTicksLogging, DoesNotMakeStreamBad) { | 1200 TEST(TimeTicksLogging, DoesNotMakeStreamBad) { |
| 1192 std::ostringstream oss; | 1201 std::ostringstream oss; |
| 1193 oss << TimeTicks(); | 1202 oss << TimeTicks(); |
| 1194 EXPECT_TRUE(oss.good()); | 1203 EXPECT_TRUE(oss.good()); |
| 1195 } | 1204 } |
| 1196 | 1205 |
| 1197 } // namespace | 1206 } // namespace |
| 1198 | 1207 |
| 1199 } // namespace base | 1208 } // namespace base |
| OLD | NEW |