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 "chrome/browser/chromeos/gdata/gdata_util.h" | 5 #include "chrome/browser/chromeos/gdata/gdata_util.h" |
6 | 6 |
7 #include "base/file_path.h" | 7 #include "base/file_path.h" |
8 #include "base/i18n/time_formatting.h" | 8 #include "base/i18n/time_formatting.h" |
| 9 #include "base/stringprintf.h" |
9 #include "base/time.h" | 10 #include "base/time.h" |
10 #include "base/utf_string_conversions.h" | 11 #include "base/utf_string_conversions.h" |
11 #include "chrome/browser/chromeos/system/timezone_settings.h" | 12 #include "chrome/browser/chromeos/system/timezone_settings.h" |
12 #include "testing/gmock/include/gmock/gmock.h" | 13 #include "testing/gmock/include/gmock/gmock.h" |
13 #include "testing/gtest/include/gtest/gtest.h" | 14 #include "testing/gtest/include/gtest/gtest.h" |
14 | 15 |
15 namespace gdata { | 16 namespace gdata { |
16 namespace util { | 17 namespace util { |
| 18 namespace { |
| 19 |
| 20 // Formats |time|'s UTC representation as "2012-07-16 15:25:13:528". |
| 21 std::string FormatTimeAsUTCString(const base::Time& time) { |
| 22 base::Time::Exploded exploded; |
| 23 time.UTCExplode(&exploded); |
| 24 return base::StringPrintf( |
| 25 "%04d-%02d-%02d %02d:%02d:%02d.%03d", |
| 26 exploded.year, exploded.month, exploded.day_of_month, |
| 27 exploded.hour, exploded.minute, exploded.second, exploded.millisecond); |
| 28 } |
| 29 |
| 30 } // namespace |
17 | 31 |
18 namespace { | 32 namespace { |
19 | 33 |
20 std::string FormatTime(const base::Time& time) { | 34 std::string FormatTime(const base::Time& time) { |
21 return UTF16ToUTF8(TimeFormatShortDateAndTime(time)); | 35 return UTF16ToUTF8(TimeFormatShortDateAndTime(time)); |
22 } | 36 } |
23 | 37 |
24 } // namespace | 38 } // namespace |
25 | 39 |
26 TEST(GDataUtilTest, IsUnderGDataMountPoint) { | 40 TEST(GDataUtilTest, IsUnderGDataMountPoint) { |
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
164 EXPECT_TRUE(GetTimeFromString("2005-08-09T09:57:00-08:00", &test_time)); | 178 EXPECT_TRUE(GetTimeFromString("2005-08-09T09:57:00-08:00", &test_time)); |
165 EXPECT_EQ(FormatTime(base::Time::FromUTCExploded(target_time2)), | 179 EXPECT_EQ(FormatTime(base::Time::FromUTCExploded(target_time2)), |
166 FormatTime(test_time)); | 180 FormatTime(test_time)); |
167 | 181 |
168 base::Time::Exploded target_time3 = {2005, 1, 0, 7, 8, 2, 0, 123}; | 182 base::Time::Exploded target_time3 = {2005, 1, 0, 7, 8, 2, 0, 123}; |
169 EXPECT_TRUE(GetTimeFromString("2005-01-07T08:02:00.123Z", &test_time)); | 183 EXPECT_TRUE(GetTimeFromString("2005-01-07T08:02:00.123Z", &test_time)); |
170 EXPECT_EQ(FormatTime(base::Time::FromUTCExploded(target_time3)), | 184 EXPECT_EQ(FormatTime(base::Time::FromUTCExploded(target_time3)), |
171 FormatTime(test_time)); | 185 FormatTime(test_time)); |
172 } | 186 } |
173 | 187 |
| 188 TEST(GDataUtilTest, FormatTimeAsString) { |
| 189 base::Time::Exploded exploded_time = {2012, 7, 0, 19, 15, 59, 13, 123}; |
| 190 base::Time time = base::Time::FromUTCExploded(exploded_time); |
| 191 EXPECT_EQ("2012-07-19T15:59:13.123Z", FormatTimeAsString(time)); |
| 192 } |
| 193 |
174 } // namespace util | 194 } // namespace util |
175 } // namespace gdata | 195 } // namespace gdata |
OLD | NEW |