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

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

Issue 2734883003: base: Make TimeDurationFormat* report failures. (Closed)
Patch Set: log locale Created 3 years, 9 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
« no previous file with comments | « ash/common/system/chromeos/power/power_status_view.cc ('k') | base/i18n/time_formatting.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 // Basic time formatting methods. These methods use the current locale 5 // Basic time formatting methods. These methods use the current locale
6 // formatting for displaying the time. 6 // formatting for displaying the time.
7 7
8 #ifndef BASE_I18N_TIME_FORMATTING_H_ 8 #ifndef BASE_I18N_TIME_FORMATTING_H_
9 #define BASE_I18N_TIME_FORMATTING_H_ 9 #define BASE_I18N_TIME_FORMATTING_H_
10 10
11 #include "base/compiler_specific.h"
11 #include "base/i18n/base_i18n_export.h" 12 #include "base/i18n/base_i18n_export.h"
12 #include "base/strings/string16.h" 13 #include "base/strings/string16.h"
13 14
14 namespace base { 15 namespace base {
15 16
16 class Time; 17 class Time;
17 class TimeDelta; 18 class TimeDelta;
18 19
19 // Argument type used to specify the hour clock type. 20 // Argument type used to specify the hour clock type.
20 enum HourClockType { 21 enum HourClockType {
(...skipping 18 matching lines...) Expand all
39 40
40 // Date formats from third_party/icu/source/i18n/unicode/udat.h. Add more as 41 // Date formats from third_party/icu/source/i18n/unicode/udat.h. Add more as
41 // necessary. 42 // necessary.
42 enum DateFormat { 43 enum DateFormat {
43 // November 2007 44 // November 2007
44 DATE_FORMAT_YEAR_MONTH, 45 DATE_FORMAT_YEAR_MONTH,
45 // Tuesday, 7 November 46 // Tuesday, 7 November
46 DATE_FORMAT_MONTH_WEEKDAY_DAY, 47 DATE_FORMAT_MONTH_WEEKDAY_DAY,
47 }; 48 };
48 49
50 // TODO(derat@chromium.org): Update all of these functions to return boolean
51 // "success" values and use out-params for formatted strings:
52 // http://crbug.com/698802
53
49 // Returns the time of day, e.g., "3:07 PM". 54 // Returns the time of day, e.g., "3:07 PM".
50 BASE_I18N_EXPORT string16 TimeFormatTimeOfDay(const Time& time); 55 BASE_I18N_EXPORT string16 TimeFormatTimeOfDay(const Time& time);
51 56
52 // Returns the time of day in 24-hour clock format with millisecond accuracy, 57 // Returns the time of day in 24-hour clock format with millisecond accuracy,
53 // e.g., "15:07:30.568" 58 // e.g., "15:07:30.568"
54 BASE_I18N_EXPORT string16 TimeFormatTimeOfDayWithMilliseconds(const Time& time); 59 BASE_I18N_EXPORT string16 TimeFormatTimeOfDayWithMilliseconds(const Time& time);
55 60
56 // Returns the time of day in the specified hour clock type. e.g. 61 // Returns the time of day in the specified hour clock type. e.g.
57 // "3:07 PM" (type == k12HourClock, ampm == kKeepAmPm). 62 // "3:07 PM" (type == k12HourClock, ampm == kKeepAmPm).
58 // "3:07" (type == k12HourClock, ampm == kDropAmPm). 63 // "3:07" (type == k12HourClock, ampm == kDropAmPm).
(...skipping 29 matching lines...) Expand all
88 BASE_I18N_EXPORT string16 TimeFormatFriendlyDate(const Time& time); 93 BASE_I18N_EXPORT string16 TimeFormatFriendlyDate(const Time& time);
89 94
90 // Formats a time using a skeleton to produce a format for different locales 95 // Formats a time using a skeleton to produce a format for different locales
91 // when an unusual time format is needed, e.g. "Feb. 2, 18:00". 96 // when an unusual time format is needed, e.g. "Feb. 2, 18:00".
92 // 97 //
93 // See http://userguide.icu-project.org/formatparse/datetime for details. 98 // See http://userguide.icu-project.org/formatparse/datetime for details.
94 BASE_I18N_EXPORT string16 TimeFormatWithPattern(const Time& time, 99 BASE_I18N_EXPORT string16 TimeFormatWithPattern(const Time& time,
95 const char* pattern); 100 const char* pattern);
96 101
97 // Formats a time duration of hours and minutes into various formats, e.g., 102 // Formats a time duration of hours and minutes into various formats, e.g.,
98 // "3:07" or "3 hours, 7 minutes". See DurationFormatWidth for details. 103 // "3:07" or "3 hours, 7 minutes", and returns true on success. See
104 // DurationFormatWidth for details.
99 // 105 //
100 // Please don't use width = DURATION_WIDTH_NUMERIC when the time duration 106 // Please don't use width = DURATION_WIDTH_NUMERIC when the time duration
101 // can possibly be larger than 24h, as the hour value will be cut below 24 107 // can possibly be larger than 24h, as the hour value will be cut below 24
102 // after formatting. 108 // after formatting.
103 // TODO(chengx): fix function output when width = DURATION_WIDTH_NUMERIC 109 // TODO(chengx): fix function output when width = DURATION_WIDTH_NUMERIC
104 // (http://crbug.com/675791) 110 // (http://crbug.com/675791)
105 BASE_I18N_EXPORT string16 TimeDurationFormat(const TimeDelta time, 111 BASE_I18N_EXPORT bool TimeDurationFormat(const TimeDelta time,
106 const DurationFormatWidth width); 112 const DurationFormatWidth width,
113 string16* out) WARN_UNUSED_RESULT;
107 114
108 // Formats a time duration of hours, minutes and seconds into various formats, 115 // Formats a time duration of hours, minutes and seconds into various formats,
109 // e.g., "3:07:30" or "3 hours, 7 minutes, 30 seconds". See DurationFormatWidth 116 // e.g., "3:07:30" or "3 hours, 7 minutes, 30 seconds", and returns true on
110 // for details. 117 // success. See DurationFormatWidth for details.
111 // 118 //
112 // Please don't use width = DURATION_WIDTH_NUMERIC when the time duration 119 // Please don't use width = DURATION_WIDTH_NUMERIC when the time duration
113 // can possibly be larger than 24h, as the hour value will be cut below 24 120 // can possibly be larger than 24h, as the hour value will be cut below 24
114 // after formatting. 121 // after formatting.
115 // TODO(chengx): fix function output when width = DURATION_WIDTH_NUMERIC 122 // TODO(chengx): fix function output when width = DURATION_WIDTH_NUMERIC
116 // (http://crbug.com/675791) 123 // (http://crbug.com/675791)
117 BASE_I18N_EXPORT string16 124 BASE_I18N_EXPORT bool TimeDurationFormatWithSeconds(
118 TimeDurationFormatWithSeconds(const TimeDelta time, 125 const TimeDelta time,
119 const DurationFormatWidth width); 126 const DurationFormatWidth width,
127 string16* out) WARN_UNUSED_RESULT;
120 128
121 // Formats a date interval into various formats, e.g. "2 December - 4 December" 129 // Formats a date interval into various formats, e.g. "2 December - 4 December"
122 // or "March 2016 - December 2016". See DateFormat for details. 130 // or "March 2016 - December 2016". See DateFormat for details.
123 BASE_I18N_EXPORT string16 DateIntervalFormat(const Time& begin_time, 131 BASE_I18N_EXPORT string16 DateIntervalFormat(const Time& begin_time,
124 const Time& end_time, 132 const Time& end_time,
125 DateFormat format); 133 DateFormat format);
126 134
127 // Gets the hour clock type of the current locale. e.g. 135 // Gets the hour clock type of the current locale. e.g.
128 // k12HourClock (en-US). 136 // k12HourClock (en-US).
129 // k24HourClock (en-GB). 137 // k24HourClock (en-GB).
130 BASE_I18N_EXPORT HourClockType GetHourClockType(); 138 BASE_I18N_EXPORT HourClockType GetHourClockType();
131 139
132 } // namespace base 140 } // namespace base
133 141
134 #endif // BASE_I18N_TIME_FORMATTING_H_ 142 #endif // BASE_I18N_TIME_FORMATTING_H_
OLDNEW
« no previous file with comments | « ash/common/system/chromeos/power/power_status_view.cc ('k') | base/i18n/time_formatting.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698