Chromium Code Reviews| 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 <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include <memory> | 9 #include <memory> |
| 10 | 10 |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 82 return UMEASFMT_WIDTH_COUNT; | 82 return UMEASFMT_WIDTH_COUNT; |
| 83 } | 83 } |
| 84 | 84 |
| 85 const char* DateFormatToString(DateFormat format) { | 85 const char* DateFormatToString(DateFormat format) { |
| 86 switch (format) { | 86 switch (format) { |
| 87 case DATE_FORMAT_YEAR_MONTH: | 87 case DATE_FORMAT_YEAR_MONTH: |
| 88 return UDAT_YEAR_MONTH; | 88 return UDAT_YEAR_MONTH; |
| 89 case DATE_FORMAT_MONTH_WEEKDAY_DAY: | 89 case DATE_FORMAT_MONTH_WEEKDAY_DAY: |
| 90 return UDAT_MONTH_WEEKDAY_DAY; | 90 return UDAT_MONTH_WEEKDAY_DAY; |
| 91 } | 91 } |
| 92 NOTREACHED(); | 92 NOTREACHED(); |
|
Jared Saul
2017/01/25 18:22:17
Remove NOTREACHED()?
Jared Saul
2017/01/26 00:15:39
Whoops, ignore this--I didn't realize this was a s
jiahuiguo
2017/01/26 05:46:13
Done.
jiahuiguo
2017/01/26 05:46:13
Done.
| |
| 93 return UDAT_YEAR_MONTH_DAY; | 93 return UDAT_YEAR_MONTH_DAY; |
| 94 } | 94 } |
| 95 | 95 |
| 96 } // namespace | 96 } // namespace |
| 97 | 97 |
| 98 string16 TimeFormatTimeOfDay(const Time& time) { | 98 string16 TimeFormatTimeOfDay(const Time& time) { |
| 99 // We can omit the locale parameter because the default should match | 99 // We can omit the locale parameter because the default should match |
| 100 // Chrome's application locale. | 100 // Chrome's application locale. |
| 101 std::unique_ptr<icu::DateFormat> formatter( | 101 std::unique_ptr<icu::DateFormat> formatter( |
| 102 icu::DateFormat::createTimeInstance(icu::DateFormat::kShort)); | 102 icu::DateFormat::createTimeInstance(icu::DateFormat::kShort)); |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 164 icu::DateFormat::createDateTimeInstance(icu::DateFormat::kFull)); | 164 icu::DateFormat::createDateTimeInstance(icu::DateFormat::kFull)); |
| 165 return TimeFormat(formatter.get(), time); | 165 return TimeFormat(formatter.get(), time); |
| 166 } | 166 } |
| 167 | 167 |
| 168 string16 TimeFormatFriendlyDate(const Time& time) { | 168 string16 TimeFormatFriendlyDate(const Time& time) { |
| 169 std::unique_ptr<icu::DateFormat> formatter( | 169 std::unique_ptr<icu::DateFormat> formatter( |
| 170 icu::DateFormat::createDateInstance(icu::DateFormat::kFull)); | 170 icu::DateFormat::createDateInstance(icu::DateFormat::kFull)); |
| 171 return TimeFormat(formatter.get(), time); | 171 return TimeFormat(formatter.get(), time); |
| 172 } | 172 } |
| 173 | 173 |
| 174 string16 TimeFormatWithPattern(const Time& time, const char* pattern) { | |
| 175 icu::SimpleDateFormat formatter = CreateSimpleDateFormatter(pattern); | |
| 176 return TimeFormat(&formatter, time); | |
| 177 } | |
| 178 | |
| 174 string16 TimeDurationFormat(const TimeDelta time, | 179 string16 TimeDurationFormat(const TimeDelta time, |
| 175 const DurationFormatWidth width) { | 180 const DurationFormatWidth width) { |
| 176 UErrorCode status = U_ZERO_ERROR; | 181 UErrorCode status = U_ZERO_ERROR; |
| 177 const int total_minutes = static_cast<int>(time.InSecondsF() / 60 + 0.5); | 182 const int total_minutes = static_cast<int>(time.InSecondsF() / 60 + 0.5); |
| 178 const int hours = total_minutes / 60; | 183 const int hours = total_minutes / 60; |
| 179 const int minutes = total_minutes % 60; | 184 const int minutes = total_minutes % 60; |
| 180 UMeasureFormatWidth u_width = DurationWidthToMeasureWidth(width); | 185 UMeasureFormatWidth u_width = DurationWidthToMeasureWidth(width); |
| 181 | 186 |
| 182 const icu::Measure measures[] = { | 187 const icu::Measure measures[] = { |
| 183 icu::Measure(hours, icu::MeasureUnit::createHour(status), status), | 188 icu::Measure(hours, icu::MeasureUnit::createHour(status), status), |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 262 // See http://userguide.icu-project.org/formatparse/datetime for details | 267 // See http://userguide.icu-project.org/formatparse/datetime for details |
| 263 // about the date/time format syntax. | 268 // about the date/time format syntax. |
| 264 if (pattern_unicode.indexOf('a') == -1) { | 269 if (pattern_unicode.indexOf('a') == -1) { |
| 265 return k24HourClock; | 270 return k24HourClock; |
| 266 } else { | 271 } else { |
| 267 return k12HourClock; | 272 return k12HourClock; |
| 268 } | 273 } |
| 269 } | 274 } |
| 270 | 275 |
| 271 } // namespace base | 276 } // namespace base |
| OLD | NEW |