| 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 153 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 |