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 153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 164 const icu::Measure measures[] = { | 164 const icu::Measure measures[] = { |
| 165 icu::Measure(hours, icu::MeasureUnit::createHour(status), status), | 165 icu::Measure(hours, icu::MeasureUnit::createHour(status), status), |
| 166 icu::Measure(minutes, icu::MeasureUnit::createMinute(status), status)}; | 166 icu::Measure(minutes, icu::MeasureUnit::createMinute(status), status)}; |
| 167 icu::MeasureFormat measure_format(icu::Locale::getDefault(), u_width, status); | 167 icu::MeasureFormat measure_format(icu::Locale::getDefault(), u_width, status); |
| 168 icu::UnicodeString formatted; | 168 icu::UnicodeString formatted; |
| 169 icu::FieldPosition ignore(icu::FieldPosition::DONT_CARE); | 169 icu::FieldPosition ignore(icu::FieldPosition::DONT_CARE); |
| 170 measure_format.formatMeasures(measures, 2, formatted, ignore, status); | 170 measure_format.formatMeasures(measures, 2, formatted, ignore, status); |
| 171 return base::string16(formatted.getBuffer(), formatted.length()); | 171 return base::string16(formatted.getBuffer(), formatted.length()); |
| 172 } | 172 } |
| 173 | 173 |
| 174 string16 TimeDurationWFormatWithSecondPrecison( | |
| 175 const TimeDelta& time, | |
| 176 const DurationFormatWidth width) { | |
| 177 UErrorCode status = U_ZERO_ERROR; | |
| 178 const int64_t total_seconds = time.InSeconds(); | |
|
brucedawson
2016/12/19 21:51:05
Consider rounding to nearest as in TimeDurationFor
chengx
2016/12/20 00:51:12
Done.
| |
| 179 int hours = total_seconds / 3600; | |
|
brucedawson
2016/12/19 21:51:05
Why no 'const' here? It seems inconsistent with to
chengx
2016/12/20 00:51:12
In icu::Measure, actually its first parameter is c
| |
| 180 int minutes = (total_seconds - hours * 3600) / 60; | |
| 181 int seconds = total_seconds % 60; | |
| 182 UMeasureFormatWidth u_width = DurationWidthToMeasureWidth(width); | |
| 183 | |
| 184 const icu::Measure measures[] = { | |
| 185 icu::Measure(hours, icu::MeasureUnit::createHour(status), status), | |
| 186 icu::Measure(minutes, icu::MeasureUnit::createMinute(status), status), | |
| 187 icu::Measure(seconds, icu::MeasureUnit::createSecond(status), status)}; | |
| 188 icu::MeasureFormat measure_format(icu::Locale::getDefault(), u_width, status); | |
| 189 icu::UnicodeString formatted; | |
| 190 icu::FieldPosition ignore(icu::FieldPosition::DONT_CARE); | |
| 191 measure_format.formatMeasures(measures, 3, formatted, ignore, status); | |
| 192 return base::string16(formatted.getBuffer(), formatted.length()); | |
| 193 } | |
| 194 | |
| 174 HourClockType GetHourClockType() { | 195 HourClockType GetHourClockType() { |
| 175 // TODO(satorux,jshin): Rework this with ures_getByKeyWithFallback() | 196 // TODO(satorux,jshin): Rework this with ures_getByKeyWithFallback() |
| 176 // once it becomes public. The short time format can be found at | 197 // once it becomes public. The short time format can be found at |
| 177 // "calendar/gregorian/DateTimePatterns/3" in the resources. | 198 // "calendar/gregorian/DateTimePatterns/3" in the resources. |
| 178 std::unique_ptr<icu::SimpleDateFormat> formatter( | 199 std::unique_ptr<icu::SimpleDateFormat> formatter( |
| 179 static_cast<icu::SimpleDateFormat*>( | 200 static_cast<icu::SimpleDateFormat*>( |
| 180 icu::DateFormat::createTimeInstance(icu::DateFormat::kShort))); | 201 icu::DateFormat::createTimeInstance(icu::DateFormat::kShort))); |
| 181 // Retrieve the short time format. | 202 // Retrieve the short time format. |
| 182 icu::UnicodeString pattern_unicode; | 203 icu::UnicodeString pattern_unicode; |
| 183 formatter->toPattern(pattern_unicode); | 204 formatter->toPattern(pattern_unicode); |
| (...skipping 21 matching lines...) Expand all Loading... | |
| 205 // See http://userguide.icu-project.org/formatparse/datetime for details | 226 // See http://userguide.icu-project.org/formatparse/datetime for details |
| 206 // about the date/time format syntax. | 227 // about the date/time format syntax. |
| 207 if (pattern_unicode.indexOf('a') == -1) { | 228 if (pattern_unicode.indexOf('a') == -1) { |
| 208 return k24HourClock; | 229 return k24HourClock; |
| 209 } else { | 230 } else { |
| 210 return k12HourClock; | 231 return k12HourClock; |
| 211 } | 232 } |
| 212 } | 233 } |
| 213 | 234 |
| 214 } // namespace base | 235 } // namespace base |
| OLD | NEW |