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 "base/logging.h" | 7 #include "base/logging.h" |
8 #include "base/memory/scoped_ptr.h" | 8 #include "base/memory/scoped_ptr.h" |
9 #include "base/utf_string_conversions.h" | 9 #include "base/utf_string_conversions.h" |
10 #include "base/time.h" | 10 #include "base/time.h" |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
68 return TimeFormatTimeOfDay(time); | 68 return TimeFormatTimeOfDay(time); |
69 } | 69 } |
70 | 70 |
71 // Generate a locale-dependent format pattern. The generator will take | 71 // Generate a locale-dependent format pattern. The generator will take |
72 // care of locale-dependent formatting issues like which separator to | 72 // care of locale-dependent formatting issues like which separator to |
73 // use (some locales use '.' instead of ':'), and where to put the am/pm | 73 // use (some locales use '.' instead of ':'), and where to put the am/pm |
74 // marker. | 74 // marker. |
75 UErrorCode status = U_ZERO_ERROR; | 75 UErrorCode status = U_ZERO_ERROR; |
76 scoped_ptr<icu::DateTimePatternGenerator> generator( | 76 scoped_ptr<icu::DateTimePatternGenerator> generator( |
77 icu::DateTimePatternGenerator::createInstance(status)); | 77 icu::DateTimePatternGenerator::createInstance(status)); |
78 CHECK(U_SUCCESS(status)); | 78 DCHECK(U_SUCCESS(status)); |
79 const char* base_pattern = (type == k12HourClock ? "ahm" : "Hm"); | 79 const char* base_pattern = (type == k12HourClock ? "ahm" : "Hm"); |
80 icu::UnicodeString generated_pattern = | 80 icu::UnicodeString generated_pattern = |
81 generator->getBestPattern(icu::UnicodeString(base_pattern), status); | 81 generator->getBestPattern(icu::UnicodeString(base_pattern), status); |
82 CHECK(U_SUCCESS(status)); | 82 DCHECK(U_SUCCESS(status)); |
83 | 83 |
84 // Then, format the time using the generated pattern. | 84 // Then, format the time using the generated pattern. |
85 icu::SimpleDateFormat formatter(generated_pattern, status); | 85 icu::SimpleDateFormat formatter(generated_pattern, status); |
86 CHECK(U_SUCCESS(status)); | 86 DCHECK(U_SUCCESS(status)); |
87 if (ampm == kKeepAmPm) { | 87 if (ampm == kKeepAmPm) { |
88 return TimeFormat(&formatter, time); | 88 return TimeFormat(&formatter, time); |
89 } else { | 89 } else { |
90 return TimeFormatWithoutAmPm(&formatter, time); | 90 return TimeFormatWithoutAmPm(&formatter, time); |
91 } | 91 } |
92 } | 92 } |
93 | 93 |
94 string16 TimeFormatShortDate(const Time& time) { | 94 string16 TimeFormatShortDate(const Time& time) { |
95 scoped_ptr<icu::DateFormat> formatter( | 95 scoped_ptr<icu::DateFormat> formatter( |
96 icu::DateFormat::createDateInstance(icu::DateFormat::kMedium)); | 96 icu::DateFormat::createDateInstance(icu::DateFormat::kMedium)); |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
155 // See http://userguide.icu-project.org/formatparse/datetime for details | 155 // See http://userguide.icu-project.org/formatparse/datetime for details |
156 // about the date/time format syntax. | 156 // about the date/time format syntax. |
157 if (pattern_unicode.indexOf('a') == -1) { | 157 if (pattern_unicode.indexOf('a') == -1) { |
158 return k24HourClock; | 158 return k24HourClock; |
159 } else { | 159 } else { |
160 return k12HourClock; | 160 return k12HourClock; |
161 } | 161 } |
162 } | 162 } |
163 | 163 |
164 } // namespace base | 164 } // namespace base |
OLD | NEW |