Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(303)

Side by Side Diff: base/i18n/time_formatting.cc

Issue 2607043002: [Autofill] Credit Card Autofill Last Used Date Experiment (Closed)
Patch Set: Add date formatter based on pattern Created 3 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 135 matching lines...) Expand 10 before | Expand all | Expand 10 after
146 icu::DateFormat::createDateTimeInstance(icu::DateFormat::kFull)); 146 icu::DateFormat::createDateTimeInstance(icu::DateFormat::kFull));
147 return TimeFormat(formatter.get(), time); 147 return TimeFormat(formatter.get(), time);
148 } 148 }
149 149
150 string16 TimeFormatFriendlyDate(const Time& time) { 150 string16 TimeFormatFriendlyDate(const Time& time) {
151 std::unique_ptr<icu::DateFormat> formatter( 151 std::unique_ptr<icu::DateFormat> formatter(
152 icu::DateFormat::createDateInstance(icu::DateFormat::kFull)); 152 icu::DateFormat::createDateInstance(icu::DateFormat::kFull));
153 return TimeFormat(formatter.get(), time); 153 return TimeFormat(formatter.get(), time);
154 } 154 }
155 155
156 string16 TimeFormatWithPattern(const Time& time, const char* pattern) {
157 icu::SimpleDateFormat formatter = CreateSimpleDateFormatter(pattern);
158 return TimeFormat(&formatter, time);
159 }
160
156 string16 TimeDurationFormat(const TimeDelta time, 161 string16 TimeDurationFormat(const TimeDelta time,
157 const DurationFormatWidth width) { 162 const DurationFormatWidth width) {
158 UErrorCode status = U_ZERO_ERROR; 163 UErrorCode status = U_ZERO_ERROR;
159 const int total_minutes = static_cast<int>(time.InSecondsF() / 60 + 0.5); 164 const int total_minutes = static_cast<int>(time.InSecondsF() / 60 + 0.5);
160 const int hours = total_minutes / 60; 165 const int hours = total_minutes / 60;
161 const int minutes = total_minutes % 60; 166 const int minutes = total_minutes % 60;
162 UMeasureFormatWidth u_width = DurationWidthToMeasureWidth(width); 167 UMeasureFormatWidth u_width = DurationWidthToMeasureWidth(width);
163 168
164 const icu::Measure measures[] = { 169 const icu::Measure measures[] = {
165 icu::Measure(hours, icu::MeasureUnit::createHour(status), status), 170 icu::Measure(hours, icu::MeasureUnit::createHour(status), status),
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
225 // See http://userguide.icu-project.org/formatparse/datetime for details 230 // See http://userguide.icu-project.org/formatparse/datetime for details
226 // about the date/time format syntax. 231 // about the date/time format syntax.
227 if (pattern_unicode.indexOf('a') == -1) { 232 if (pattern_unicode.indexOf('a') == -1) {
228 return k24HourClock; 233 return k24HourClock;
229 } else { 234 } else {
230 return k12HourClock; 235 return k12HourClock;
231 } 236 }
232 } 237 }
233 238
234 } // namespace base 239 } // namespace base
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698