OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/i18n/time_formatting.h" | 5 #include "base/i18n/time_formatting.h" |
6 | 6 |
7 #include <memory> | 7 #include <memory> |
8 | 8 |
9 #include "base/i18n/rtl.h" | 9 #include "base/i18n/rtl.h" |
| 10 #include "base/i18n/unicodestring.h" |
10 #include "base/strings/utf_string_conversions.h" | 11 #include "base/strings/utf_string_conversions.h" |
11 #include "base/test/icu_test_util.h" | 12 #include "base/test/icu_test_util.h" |
12 #include "base/time/time.h" | 13 #include "base/time/time.h" |
13 #include "testing/gtest/include/gtest/gtest.h" | 14 #include "testing/gtest/include/gtest/gtest.h" |
14 #include "third_party/icu/source/common/unicode/uversion.h" | 15 #include "third_party/icu/source/common/unicode/uversion.h" |
15 #include "third_party/icu/source/i18n/unicode/calendar.h" | 16 #include "third_party/icu/source/i18n/unicode/calendar.h" |
16 #include "third_party/icu/source/i18n/unicode/timezone.h" | 17 #include "third_party/icu/source/i18n/unicode/timezone.h" |
17 #include "third_party/icu/source/i18n/unicode/tzfmt.h" | 18 #include "third_party/icu/source/i18n/unicode/tzfmt.h" |
18 | 19 |
19 namespace base { | 20 namespace base { |
(...skipping 10 matching lines...) Expand all Loading... |
30 string16 GetShortTimeZone(const Time& time) { | 31 string16 GetShortTimeZone(const Time& time) { |
31 UErrorCode status = U_ZERO_ERROR; | 32 UErrorCode status = U_ZERO_ERROR; |
32 std::unique_ptr<icu::TimeZone> zone(icu::TimeZone::createDefault()); | 33 std::unique_ptr<icu::TimeZone> zone(icu::TimeZone::createDefault()); |
33 std::unique_ptr<icu::TimeZoneFormat> zone_formatter( | 34 std::unique_ptr<icu::TimeZoneFormat> zone_formatter( |
34 icu::TimeZoneFormat::createInstance(icu::Locale::getDefault(), status)); | 35 icu::TimeZoneFormat::createInstance(icu::Locale::getDefault(), status)); |
35 EXPECT_TRUE(U_SUCCESS(status)); | 36 EXPECT_TRUE(U_SUCCESS(status)); |
36 icu::UnicodeString name; | 37 icu::UnicodeString name; |
37 zone_formatter->format(UTZFMT_STYLE_SPECIFIC_SHORT, *zone, | 38 zone_formatter->format(UTZFMT_STYLE_SPECIFIC_SHORT, *zone, |
38 static_cast<UDate>(time.ToDoubleT() * 1000), | 39 static_cast<UDate>(time.ToDoubleT() * 1000), |
39 name, nullptr); | 40 name, nullptr); |
40 return string16(name.getBuffer(), name.length()); | 41 return i18n::UnicodeStringToString16(name); |
41 } | 42 } |
42 | 43 |
43 // Calls TimeDurationFormat() with |delta| and |width| and returns the resulting | 44 // Calls TimeDurationFormat() with |delta| and |width| and returns the resulting |
44 // string. On failure, adds a failed expectation and returns an empty string. | 45 // string. On failure, adds a failed expectation and returns an empty string. |
45 string16 TimeDurationFormatString(const TimeDelta& delta, | 46 string16 TimeDurationFormatString(const TimeDelta& delta, |
46 DurationFormatWidth width) { | 47 DurationFormatWidth width) { |
47 string16 str; | 48 string16 str; |
48 EXPECT_TRUE(TimeDurationFormat(delta, width, &str)) | 49 EXPECT_TRUE(TimeDurationFormat(delta, width, &str)) |
49 << "Failed to format " << delta.ToInternalValue() << " with width " | 50 << "Failed to format " << delta.ToInternalValue() << " with width " |
50 << width; | 51 << width; |
(...skipping 327 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
378 Time end_time; | 379 Time end_time; |
379 EXPECT_TRUE(Time::FromLocalExploded(kTestIntervalEndTimeExploded, &end_time)); | 380 EXPECT_TRUE(Time::FromLocalExploded(kTestIntervalEndTimeExploded, &end_time)); |
380 | 381 |
381 EXPECT_EQ( | 382 EXPECT_EQ( |
382 WideToUTF16(L"Saturday, April 30 – Saturday, May 28"), | 383 WideToUTF16(L"Saturday, April 30 – Saturday, May 28"), |
383 DateIntervalFormat(begin_time, end_time, DATE_FORMAT_MONTH_WEEKDAY_DAY)); | 384 DateIntervalFormat(begin_time, end_time, DATE_FORMAT_MONTH_WEEKDAY_DAY)); |
384 } | 385 } |
385 | 386 |
386 } // namespace | 387 } // namespace |
387 } // namespace base | 388 } // namespace base |
OLD | NEW |