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) | |
|
yoshiki
2012/09/10 05:34:50
It is better to use "OS_CHROMEOS" rather than "CHR
nhiroki
2012/09/10 07:17:39
Done in the separate patch (http://codereview.chro
| |
| 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 // TODO(yoshiki): Find platform independent way to get/set local timezone. | |
| 27 #if defined(CHROMEOS) | |
|
yoshiki
2012/09/10 05:34:50
ditto
nhiroki
2012/09/10 07:17:39
Done in the separate patch (http://codereview.chro
| |
| 23 TEST(GDataUtilTest, GetTimeFromStringLocalTimezone) { | 28 TEST(GDataUtilTest, GetTimeFromStringLocalTimezone) { |
| 24 // Creates time object GMT. | 29 // Creates time object GMT. |
| 25 base::Time::Exploded exploded = {2012, 7, 0, 14, 1, 3, 21, 151}; | 30 base::Time::Exploded exploded = {2012, 7, 0, 14, 1, 3, 21, 151}; |
| 26 base::Time target_time = base::Time::FromUTCExploded(exploded); | 31 base::Time target_time = base::Time::FromUTCExploded(exploded); |
| 27 | 32 |
| 28 // Creates time object as the local time. | 33 // Creates time object as the local time. |
| 29 base::Time test_time; | 34 base::Time test_time; |
| 30 ASSERT_TRUE(GetTimeFromString("2012-07-14T01:03:21.151", &test_time)); | 35 ASSERT_TRUE(GetTimeFromString("2012-07-14T01:03:21.151", &test_time)); |
| 31 | 36 |
| 32 // Gets the offset between the local time and GMT. | 37 // 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}; | 83 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)); | 84 EXPECT_TRUE(GetTimeFromString("2005-08-09T09:57:00-08:00", &test_time)); |
| 80 EXPECT_EQ(FormatTime(base::Time::FromUTCExploded(target_time2)), | 85 EXPECT_EQ(FormatTime(base::Time::FromUTCExploded(target_time2)), |
| 81 FormatTime(test_time)); | 86 FormatTime(test_time)); |
| 82 | 87 |
| 83 base::Time::Exploded target_time3 = {2005, 1, 0, 7, 8, 2, 0, 123}; | 88 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)); | 89 EXPECT_TRUE(GetTimeFromString("2005-01-07T08:02:00.123Z", &test_time)); |
| 85 EXPECT_EQ(FormatTime(base::Time::FromUTCExploded(target_time3)), | 90 EXPECT_EQ(FormatTime(base::Time::FromUTCExploded(target_time3)), |
| 86 FormatTime(test_time)); | 91 FormatTime(test_time)); |
| 87 } | 92 } |
| 93 #endif | |
| 88 | 94 |
| 89 TEST(GDataUtilTest, FormatTimeAsString) { | 95 TEST(GDataUtilTest, FormatTimeAsString) { |
| 90 base::Time::Exploded exploded_time = {2012, 7, 0, 19, 15, 59, 13, 123}; | 96 base::Time::Exploded exploded_time = {2012, 7, 0, 19, 15, 59, 13, 123}; |
| 91 base::Time time = base::Time::FromUTCExploded(exploded_time); | 97 base::Time time = base::Time::FromUTCExploded(exploded_time); |
| 92 EXPECT_EQ("2012-07-19T15:59:13.123Z", FormatTimeAsString(time)); | 98 EXPECT_EQ("2012-07-19T15:59:13.123Z", FormatTimeAsString(time)); |
| 93 } | 99 } |
| 94 | 100 |
| 95 } // namespace util | 101 } // namespace util |
| 96 } // namespace gdata | 102 } // namespace gdata |
| OLD | NEW |