| 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 "chrome/common/time_format.h" | 5 #include "chrome/common/time_format.h" |
| 6 | 6 |
| 7 #include <vector> | 7 #include <vector> |
| 8 | 8 |
| 9 #include "base/lazy_instance.h" | 9 #include "base/lazy_instance.h" |
| 10 #include "base/logging.h" | 10 #include "base/logging.h" |
| (...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 179 const icu::PluralRules& rules, int index, FormatType format_type); | 179 const icu::PluralRules& rules, int index, FormatType format_type); |
| 180 | 180 |
| 181 DISALLOW_COPY_AND_ASSIGN(TimeFormatter); | 181 DISALLOW_COPY_AND_ASSIGN(TimeFormatter); |
| 182 }; | 182 }; |
| 183 | 183 |
| 184 static base::LazyInstance<TimeFormatter> g_time_formatter = | 184 static base::LazyInstance<TimeFormatter> g_time_formatter = |
| 185 LAZY_INSTANCE_INITIALIZER; | 185 LAZY_INSTANCE_INITIALIZER; |
| 186 | 186 |
| 187 void TimeFormatter::BuildFormats( | 187 void TimeFormatter::BuildFormats( |
| 188 FormatType format_type, std::vector<icu::PluralFormat*>* time_formats) { | 188 FormatType format_type, std::vector<icu::PluralFormat*>* time_formats) { |
| 189 static const icu::UnicodeString kKeywords[] = { | 189 const icu::UnicodeString kKeywords[] = { |
| 190 UNICODE_STRING_SIMPLE("other"), UNICODE_STRING_SIMPLE("one"), | 190 UNICODE_STRING_SIMPLE("other"), UNICODE_STRING_SIMPLE("one"), |
| 191 UNICODE_STRING_SIMPLE("zero"), UNICODE_STRING_SIMPLE("two"), | 191 UNICODE_STRING_SIMPLE("zero"), UNICODE_STRING_SIMPLE("two"), |
| 192 UNICODE_STRING_SIMPLE("few"), UNICODE_STRING_SIMPLE("many") | 192 UNICODE_STRING_SIMPLE("few"), UNICODE_STRING_SIMPLE("many") |
| 193 }; | 193 }; |
| 194 UErrorCode err = U_ZERO_ERROR; | 194 UErrorCode err = U_ZERO_ERROR; |
| 195 scoped_ptr<icu::PluralRules> rules( | 195 scoped_ptr<icu::PluralRules> rules( |
| 196 icu::PluralRules::forLocale(icu::Locale::getDefault(), err)); | 196 icu::PluralRules::forLocale(icu::Locale::getDefault(), err)); |
| 197 if (U_FAILURE(err)) { | 197 if (U_FAILURE(err)) { |
| 198 err = U_ZERO_ERROR; | 198 err = U_ZERO_ERROR; |
| 199 icu::UnicodeString fallback_rules("one: n is 1", -1, US_INV); | 199 icu::UnicodeString fallback_rules("one: n is 1", -1, US_INV); |
| (...skipping 30 matching lines...) Expand all Loading... |
| 230 // Reset it so that next ICU call can proceed. | 230 // Reset it so that next ICU call can proceed. |
| 231 err = U_ZERO_ERROR; | 231 err = U_ZERO_ERROR; |
| 232 } | 232 } |
| 233 } | 233 } |
| 234 } | 234 } |
| 235 | 235 |
| 236 // Create a hard-coded fallback plural format. This will never be called | 236 // Create a hard-coded fallback plural format. This will never be called |
| 237 // unless translators make a mistake. | 237 // unless translators make a mistake. |
| 238 icu::PluralFormat* TimeFormatter::createFallbackFormat( | 238 icu::PluralFormat* TimeFormatter::createFallbackFormat( |
| 239 const icu::PluralRules& rules, int index, FormatType format_type) { | 239 const icu::PluralRules& rules, int index, FormatType format_type) { |
| 240 static const icu::UnicodeString kUnits[4][2] = { | 240 const icu::UnicodeString kUnits[4][2] = { |
| 241 { UNICODE_STRING_SIMPLE("sec"), UNICODE_STRING_SIMPLE("secs") }, | 241 { UNICODE_STRING_SIMPLE("sec"), UNICODE_STRING_SIMPLE("secs") }, |
| 242 { UNICODE_STRING_SIMPLE("min"), UNICODE_STRING_SIMPLE("mins") }, | 242 { UNICODE_STRING_SIMPLE("min"), UNICODE_STRING_SIMPLE("mins") }, |
| 243 { UNICODE_STRING_SIMPLE("hour"), UNICODE_STRING_SIMPLE("hours") }, | 243 { UNICODE_STRING_SIMPLE("hour"), UNICODE_STRING_SIMPLE("hours") }, |
| 244 { UNICODE_STRING_SIMPLE("day"), UNICODE_STRING_SIMPLE("days") } | 244 { UNICODE_STRING_SIMPLE("day"), UNICODE_STRING_SIMPLE("days") } |
| 245 }; | 245 }; |
| 246 icu::UnicodeString suffix(GetFallbackFormatSuffix(format_type), -1, US_INV); | 246 icu::UnicodeString suffix(GetFallbackFormatSuffix(format_type), -1, US_INV); |
| 247 icu::UnicodeString pattern; | 247 icu::UnicodeString pattern; |
| 248 if (rules.isKeyword(UNICODE_STRING_SIMPLE("one"))) { | 248 if (rules.isKeyword(UNICODE_STRING_SIMPLE("one"))) { |
| 249 pattern += UNICODE_STRING_SIMPLE("one{# ") + kUnits[index][0] + suffix; | 249 pattern += UNICODE_STRING_SIMPLE("one{# ") + kUnits[index][0] + suffix; |
| 250 } | 250 } |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 328 | 328 |
| 329 // Filter out "today" and "yesterday" | 329 // Filter out "today" and "yesterday" |
| 330 if (time >= midnight_today) | 330 if (time >= midnight_today) |
| 331 return l10n_util::GetStringUTF16(IDS_PAST_TIME_TODAY); | 331 return l10n_util::GetStringUTF16(IDS_PAST_TIME_TODAY); |
| 332 else if (time >= midnight_today - | 332 else if (time >= midnight_today - |
| 333 TimeDelta::FromMicroseconds(Time::kMicrosecondsPerDay)) | 333 TimeDelta::FromMicroseconds(Time::kMicrosecondsPerDay)) |
| 334 return l10n_util::GetStringUTF16(IDS_PAST_TIME_YESTERDAY); | 334 return l10n_util::GetStringUTF16(IDS_PAST_TIME_YESTERDAY); |
| 335 | 335 |
| 336 return string16(); | 336 return string16(); |
| 337 } | 337 } |
| OLD | NEW |