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 // 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 |
(...skipping 28 matching lines...) Expand all Loading... | |
39 | 39 |
40 // Date formats from third_party/icu/source/i18n/unicode/udat.h. Add more as | 40 // Date formats from third_party/icu/source/i18n/unicode/udat.h. Add more as |
41 // necessary. | 41 // necessary. |
42 enum DateFormat { | 42 enum DateFormat { |
43 // November 2007 | 43 // November 2007 |
44 DATE_FORMAT_YEAR_MONTH, | 44 DATE_FORMAT_YEAR_MONTH, |
45 // Tuesday, 7 November | 45 // Tuesday, 7 November |
46 DATE_FORMAT_MONTH_WEEKDAY_DAY, | 46 DATE_FORMAT_MONTH_WEEKDAY_DAY, |
47 }; | 47 }; |
48 | 48 |
49 // TODO(derat@chromium.org): Update all of these functions to return boolean | |
50 // "success" values and use out-params for formatted strings: | |
51 // http://crbug.com/698802 | |
52 | |
49 // Returns the time of day, e.g., "3:07 PM". | 53 // Returns the time of day, e.g., "3:07 PM". |
50 BASE_I18N_EXPORT string16 TimeFormatTimeOfDay(const Time& time); | 54 BASE_I18N_EXPORT string16 TimeFormatTimeOfDay(const Time& time); |
51 | 55 |
52 // Returns the time of day in 24-hour clock format with millisecond accuracy, | 56 // Returns the time of day in 24-hour clock format with millisecond accuracy, |
53 // e.g., "15:07:30.568" | 57 // e.g., "15:07:30.568" |
54 BASE_I18N_EXPORT string16 TimeFormatTimeOfDayWithMilliseconds(const Time& time); | 58 BASE_I18N_EXPORT string16 TimeFormatTimeOfDayWithMilliseconds(const Time& time); |
55 | 59 |
56 // Returns the time of day in the specified hour clock type. e.g. | 60 // Returns the time of day in the specified hour clock type. e.g. |
57 // "3:07 PM" (type == k12HourClock, ampm == kKeepAmPm). | 61 // "3:07 PM" (type == k12HourClock, ampm == kKeepAmPm). |
58 // "3:07" (type == k12HourClock, ampm == kDropAmPm). | 62 // "3:07" (type == k12HourClock, ampm == kDropAmPm). |
(...skipping 29 matching lines...) Expand all Loading... | |
88 BASE_I18N_EXPORT string16 TimeFormatFriendlyDate(const Time& time); | 92 BASE_I18N_EXPORT string16 TimeFormatFriendlyDate(const Time& time); |
89 | 93 |
90 // Formats a time using a skeleton to produce a format for different locales | 94 // 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". | 95 // when an unusual time format is needed, e.g. "Feb. 2, 18:00". |
92 // | 96 // |
93 // See http://userguide.icu-project.org/formatparse/datetime for details. | 97 // See http://userguide.icu-project.org/formatparse/datetime for details. |
94 BASE_I18N_EXPORT string16 TimeFormatWithPattern(const Time& time, | 98 BASE_I18N_EXPORT string16 TimeFormatWithPattern(const Time& time, |
95 const char* pattern); | 99 const char* pattern); |
96 | 100 |
97 // Formats a time duration of hours and minutes into various formats, e.g., | 101 // 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. | 102 // "3:07" or "3 hours, 7 minutes", and returns true on success. See |
103 // DurationFormatWidth for details. | |
99 // | 104 // |
100 // Please don't use width = DURATION_WIDTH_NUMERIC when the time duration | 105 // 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 | 106 // can possibly be larger than 24h, as the hour value will be cut below 24 |
102 // after formatting. | 107 // after formatting. |
103 // TODO(chengx): fix function output when width = DURATION_WIDTH_NUMERIC | 108 // TODO(chengx): fix function output when width = DURATION_WIDTH_NUMERIC |
104 // (http://crbug.com/675791) | 109 // (http://crbug.com/675791) |
105 BASE_I18N_EXPORT string16 TimeDurationFormat(const TimeDelta time, | 110 BASE_I18N_EXPORT bool TimeDurationFormat(const TimeDelta time, |
bruthig
2017/03/06 21:12:38
Consider using the WARN_UNUSED_RESULT macro here.
Daniel Erat
2017/03/06 21:24:32
sure, sounds good.
| |
106 const DurationFormatWidth width); | 111 const DurationFormatWidth width, |
112 string16* out); | |
107 | 113 |
108 // Formats a time duration of hours, minutes and seconds into various formats, | 114 // 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 | 115 // e.g., "3:07:30" or "3 hours, 7 minutes, 30 seconds", and returns true on |
110 // for details. | 116 // success. See DurationFormatWidth for details. |
111 // | 117 // |
112 // Please don't use width = DURATION_WIDTH_NUMERIC when the time duration | 118 // 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 | 119 // can possibly be larger than 24h, as the hour value will be cut below 24 |
114 // after formatting. | 120 // after formatting. |
115 // TODO(chengx): fix function output when width = DURATION_WIDTH_NUMERIC | 121 // TODO(chengx): fix function output when width = DURATION_WIDTH_NUMERIC |
116 // (http://crbug.com/675791) | 122 // (http://crbug.com/675791) |
117 BASE_I18N_EXPORT string16 | 123 BASE_I18N_EXPORT bool TimeDurationFormatWithSeconds( |
118 TimeDurationFormatWithSeconds(const TimeDelta time, | 124 const TimeDelta time, |
119 const DurationFormatWidth width); | 125 const DurationFormatWidth width, |
126 string16* out); | |
120 | 127 |
121 // Formats a date interval into various formats, e.g. "2 December - 4 December" | 128 // Formats a date interval into various formats, e.g. "2 December - 4 December" |
122 // or "March 2016 - December 2016". See DateFormat for details. | 129 // or "March 2016 - December 2016". See DateFormat for details. |
123 BASE_I18N_EXPORT string16 DateIntervalFormat(const Time& begin_time, | 130 BASE_I18N_EXPORT string16 DateIntervalFormat(const Time& begin_time, |
124 const Time& end_time, | 131 const Time& end_time, |
125 DateFormat format); | 132 DateFormat format); |
126 | 133 |
127 // Gets the hour clock type of the current locale. e.g. | 134 // Gets the hour clock type of the current locale. e.g. |
128 // k12HourClock (en-US). | 135 // k12HourClock (en-US). |
129 // k24HourClock (en-GB). | 136 // k24HourClock (en-GB). |
130 BASE_I18N_EXPORT HourClockType GetHourClockType(); | 137 BASE_I18N_EXPORT HourClockType GetHourClockType(); |
131 | 138 |
132 } // namespace base | 139 } // namespace base |
133 | 140 |
134 #endif // BASE_I18N_TIME_FORMATTING_H_ | 141 #endif // BASE_I18N_TIME_FORMATTING_H_ |
OLD | NEW |