Chromium Code Reviews| 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/google_apis/gdata_util.h" |
| 6 | 6 |
| 7 #include "base/i18n/time_formatting.h" | 7 #include "base/i18n/time_formatting.h" |
| 8 #include "base/time.h" | 8 #include "base/time.h" |
| 9 #include "base/utf_string_conversions.h" | 9 #include "base/utf_string_conversions.h" |
| 10 #include "testing/gtest/include/gtest/gtest.h" | |
| 11 | |
| 12 #if defined(CHROMEOS) | |
| 10 #include "chrome/browser/chromeos/system/timezone_settings.h" | 13 #include "chrome/browser/chromeos/system/timezone_settings.h" |
| 11 #include "testing/gtest/include/gtest/gtest.h" | 14 #endif |
| 12 | 15 |
| 13 namespace gdata { | 16 namespace gdata { |
| 14 namespace util { | 17 namespace util { |
| 15 namespace { | 18 namespace { |
| 16 | 19 |
| 17 std::string FormatTime(const base::Time& time) { | 20 std::string FormatTime(const base::Time& time) { |
| 18 return UTF16ToUTF8(TimeFormatShortDateAndTime(time)); | 21 return UTF16ToUTF8(TimeFormatShortDateAndTime(time)); |
| 19 } | 22 } |
| 20 | 23 |
| 21 } // namespace | 24 } // namespace |
| 22 | 25 |
| 26 #if defined(CHROMEOS) | |
|
kochi
2012/09/07 06:56:21
Please add
TODO(yoshiki): Find platform independen
nhiroki
2012/09/07 09:06:26
Done.
| |
| 23 TEST(GDataUtilTest, GetTimeFromStringLocalTimezone) { | 27 TEST(GDataUtilTest, GetTimeFromStringLocalTimezone) { |
| 24 // Creates time object GMT. | 28 // Creates time object GMT. |
| 25 base::Time::Exploded exploded = {2012, 7, 0, 14, 1, 3, 21, 151}; | 29 base::Time::Exploded exploded = {2012, 7, 0, 14, 1, 3, 21, 151}; |
| 26 base::Time target_time = base::Time::FromUTCExploded(exploded); | 30 base::Time target_time = base::Time::FromUTCExploded(exploded); |
| 27 | 31 |
| 28 // Creates time object as the local time. | 32 // Creates time object as the local time. |
| 29 base::Time test_time; | 33 base::Time test_time; |
| 30 ASSERT_TRUE(GetTimeFromString("2012-07-14T01:03:21.151", &test_time)); | 34 ASSERT_TRUE(GetTimeFromString("2012-07-14T01:03:21.151", &test_time)); |
| 31 | 35 |
| 32 // Gets the offset between the local time and GMT. | 36 // Gets the offset between the local time and GMT. |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 78 base::Time::Exploded target_time2 = {2005, 8, 0, 9, 17, 57, 0, 0}; | 82 base::Time::Exploded target_time2 = {2005, 8, 0, 9, 17, 57, 0, 0}; |
| 79 EXPECT_TRUE(GetTimeFromString("2005-08-09T09:57:00-08:00", &test_time)); | 83 EXPECT_TRUE(GetTimeFromString("2005-08-09T09:57:00-08:00", &test_time)); |
| 80 EXPECT_EQ(FormatTime(base::Time::FromUTCExploded(target_time2)), | 84 EXPECT_EQ(FormatTime(base::Time::FromUTCExploded(target_time2)), |
| 81 FormatTime(test_time)); | 85 FormatTime(test_time)); |
| 82 | 86 |
| 83 base::Time::Exploded target_time3 = {2005, 1, 0, 7, 8, 2, 0, 123}; | 87 base::Time::Exploded target_time3 = {2005, 1, 0, 7, 8, 2, 0, 123}; |
| 84 EXPECT_TRUE(GetTimeFromString("2005-01-07T08:02:00.123Z", &test_time)); | 88 EXPECT_TRUE(GetTimeFromString("2005-01-07T08:02:00.123Z", &test_time)); |
| 85 EXPECT_EQ(FormatTime(base::Time::FromUTCExploded(target_time3)), | 89 EXPECT_EQ(FormatTime(base::Time::FromUTCExploded(target_time3)), |
| 86 FormatTime(test_time)); | 90 FormatTime(test_time)); |
| 87 } | 91 } |
| 92 #endif | |
| 88 | 93 |
| 89 TEST(GDataUtilTest, FormatTimeAsString) { | 94 TEST(GDataUtilTest, FormatTimeAsString) { |
| 90 base::Time::Exploded exploded_time = {2012, 7, 0, 19, 15, 59, 13, 123}; | 95 base::Time::Exploded exploded_time = {2012, 7, 0, 19, 15, 59, 13, 123}; |
| 91 base::Time time = base::Time::FromUTCExploded(exploded_time); | 96 base::Time time = base::Time::FromUTCExploded(exploded_time); |
| 92 EXPECT_EQ("2012-07-19T15:59:13.123Z", FormatTimeAsString(time)); | 97 EXPECT_EQ("2012-07-19T15:59:13.123Z", FormatTimeAsString(time)); |
| 93 } | 98 } |
| 94 | 99 |
| 95 } // namespace util | 100 } // namespace util |
| 96 } // namespace gdata | 101 } // namespace gdata |
| OLD | NEW |