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

Side by Side Diff: base/time_unittest.cc

Issue 10536061: Add Javascript time methods to base::Time. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 6 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
« base/time.cc ('K') | « base/time.cc ('k') | no next file » | 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) 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.h" 5 #include "base/time.h"
6 6
7 #include <time.h> 7 #include <time.h>
8 8
9 #include "base/compiler_specific.h" 9 #include "base/compiler_specific.h"
10 #include "base/threading/platform_thread.h" 10 #include "base/threading/platform_thread.h"
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
81 EXPECT_EQ(now_t_1, now_t_2); 81 EXPECT_EQ(now_t_1, now_t_2);
82 82
83 EXPECT_EQ(10, Time().FromTimeT(10).ToTimeT()); 83 EXPECT_EQ(10, Time().FromTimeT(10).ToTimeT());
84 EXPECT_EQ(10.0, Time().FromTimeT(10).ToDoubleT()); 84 EXPECT_EQ(10.0, Time().FromTimeT(10).ToDoubleT());
85 85
86 // Conversions of 0 should stay 0. 86 // Conversions of 0 should stay 0.
87 EXPECT_EQ(0, Time().ToTimeT()); 87 EXPECT_EQ(0, Time().ToTimeT());
88 EXPECT_EQ(0, Time::FromTimeT(0).ToInternalValue()); 88 EXPECT_EQ(0, Time::FromTimeT(0).ToInternalValue());
89 } 89 }
90 90
91 // Test conversions to/from javascript time.
92 TEST_F(TimeTest, JsTime) {
93 Time epoch = Time::FromJsTime(0.0);
94 EXPECT_EQ(epoch, Time::UnixEpoch());
95 Time t = Time::FromJsTime(700000.3);
96 EXPECT_EQ(700.0003, t.ToDoubleT());
97 t = Time::FromDoubleT(800.73);
98 EXPECT_EQ(800730.0, t.ToJsTime());
99 }
100
91 TEST_F(TimeTest, FromExplodedWithMilliseconds) { 101 TEST_F(TimeTest, FromExplodedWithMilliseconds) {
92 // Some platform implementations of FromExploded are liable to drop 102 // Some platform implementations of FromExploded are liable to drop
93 // milliseconds if we aren't careful. 103 // milliseconds if we aren't careful.
94 Time now = Time::NowFromSystemTime(); 104 Time now = Time::NowFromSystemTime();
95 Time::Exploded exploded1 = {0}; 105 Time::Exploded exploded1 = {0};
96 now.UTCExplode(&exploded1); 106 now.UTCExplode(&exploded1);
97 exploded1.millisecond = 500; 107 exploded1.millisecond = 500;
98 Time time = Time::FromUTCExploded(exploded1); 108 Time time = Time::FromUTCExploded(exploded1);
99 Time::Exploded exploded2 = {0}; 109 Time::Exploded exploded2 = {0};
100 time.UTCExplode(&exploded2); 110 time.UTCExplode(&exploded2);
(...skipping 486 matching lines...) Expand 10 before | Expand all | Expand 10 after
587 exploded.minute = 0; 597 exploded.minute = 0;
588 exploded.second = 0; 598 exploded.second = 0;
589 exploded.millisecond = 0; 599 exploded.millisecond = 0;
590 Time t = Time::FromUTCExploded(exploded); 600 Time t = Time::FromUTCExploded(exploded);
591 // Unix 1970 epoch. 601 // Unix 1970 epoch.
592 EXPECT_EQ(GG_INT64_C(11644473600000000), t.ToInternalValue()); 602 EXPECT_EQ(GG_INT64_C(11644473600000000), t.ToInternalValue());
593 603
594 // We can't test 1601 epoch, since the system time functions on Linux 604 // We can't test 1601 epoch, since the system time functions on Linux
595 // only compute years starting from 1900. 605 // only compute years starting from 1900.
596 } 606 }
OLDNEW
« base/time.cc ('K') | « base/time.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698