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 |
11 #include "base/i18n/base_i18n_export.h" | 11 #include "base/i18n/base_i18n_export.h" |
12 #include "base/strings/string16.h" | 12 #include "base/strings/string16.h" |
13 | 13 |
14 namespace base { | 14 namespace base { |
15 | 15 |
16 class Time; | 16 class Time; |
| 17 class TimeDelta; |
17 | 18 |
18 // Argument type used to specify the hour clock type. | 19 // Argument type used to specify the hour clock type. |
19 enum HourClockType { | 20 enum HourClockType { |
20 k12HourClock, // Uses 1-12. e.g., "3:07 PM" | 21 k12HourClock, // Uses 1-12. e.g., "3:07 PM" |
21 k24HourClock, // Uses 0-23. e.g., "15:07" | 22 k24HourClock, // Uses 0-23. e.g., "15:07" |
22 }; | 23 }; |
23 | 24 |
24 // Argument type used to specify whether or not to include AM/PM sign. | 25 // Argument type used to specify whether or not to include AM/PM sign. |
25 enum AmPmClockType { | 26 enum AmPmClockType { |
26 kDropAmPm, // Drops AM/PM sign. e.g., "3:07" | 27 kDropAmPm, // Drops AM/PM sign. e.g., "3:07" |
27 kKeepAmPm, // Keeps AM/PM sign. e.g., "3:07 PM" | 28 kKeepAmPm, // Keeps AM/PM sign. e.g., "3:07 PM" |
28 }; | 29 }; |
29 | 30 |
| 31 // Should match UMeasureFormatWidth in measfmt.h; replicated here to avoid |
| 32 // requiring third_party/icu dependencies with this file. |
| 33 enum DurationFormatWidth { |
| 34 DURATION_WIDTH_WIDE, // "3 hours, 7 minutes" |
| 35 DURATION_WIDTH_SHORT, // "3 hr, 7 min" |
| 36 DURATION_WIDTH_NARROW, // "3h 7m" |
| 37 DURATION_WIDTH_NUMERIC // "3:07" |
| 38 }; |
| 39 |
30 // Returns the time of day, e.g., "3:07 PM". | 40 // Returns the time of day, e.g., "3:07 PM". |
31 BASE_I18N_EXPORT string16 TimeFormatTimeOfDay(const Time& time); | 41 BASE_I18N_EXPORT string16 TimeFormatTimeOfDay(const Time& time); |
32 | 42 |
33 // Returns the time of day in 24-hour clock format with millisecond accuracy, | 43 // Returns the time of day in 24-hour clock format with millisecond accuracy, |
34 // e.g., "15:07:30.568" | 44 // e.g., "15:07:30.568" |
35 BASE_I18N_EXPORT string16 TimeFormatTimeOfDayWithMilliseconds(const Time& time); | 45 BASE_I18N_EXPORT string16 TimeFormatTimeOfDayWithMilliseconds(const Time& time); |
36 | 46 |
37 // Returns the time of day in the specified hour clock type. e.g. | 47 // Returns the time of day in the specified hour clock type. e.g. |
38 // "3:07 PM" (type == k12HourClock, ampm == kKeepAmPm). | 48 // "3:07 PM" (type == k12HourClock, ampm == kKeepAmPm). |
39 // "3:07" (type == k12HourClock, ampm == kDropAmPm). | 49 // "3:07" (type == k12HourClock, ampm == kDropAmPm). |
(...skipping 18 matching lines...) Expand all Loading... |
58 TimeFormatShortDateAndTimeWithTimeZone(const Time& time); | 68 TimeFormatShortDateAndTimeWithTimeZone(const Time& time); |
59 | 69 |
60 // Formats a time in a friendly sentence format, e.g. | 70 // Formats a time in a friendly sentence format, e.g. |
61 // "Monday, March 6, 2008 2:44:30 PM". | 71 // "Monday, March 6, 2008 2:44:30 PM". |
62 BASE_I18N_EXPORT string16 TimeFormatFriendlyDateAndTime(const Time& time); | 72 BASE_I18N_EXPORT string16 TimeFormatFriendlyDateAndTime(const Time& time); |
63 | 73 |
64 // Formats a time in a friendly sentence format, e.g. | 74 // Formats a time in a friendly sentence format, e.g. |
65 // "Monday, March 6, 2008". | 75 // "Monday, March 6, 2008". |
66 BASE_I18N_EXPORT string16 TimeFormatFriendlyDate(const Time& time); | 76 BASE_I18N_EXPORT string16 TimeFormatFriendlyDate(const Time& time); |
67 | 77 |
| 78 // Formats a time duration of hours and minutes into various formats, e.g., |
| 79 // "3:07" or "3 hours, 7 minutes". See DurationFormatWidth for details. |
| 80 BASE_I18N_EXPORT string16 TimeDurationFormat(const TimeDelta& time, |
| 81 const DurationFormatWidth width); |
| 82 |
68 // Gets the hour clock type of the current locale. e.g. | 83 // Gets the hour clock type of the current locale. e.g. |
69 // k12HourClock (en-US). | 84 // k12HourClock (en-US). |
70 // k24HourClock (en-GB). | 85 // k24HourClock (en-GB). |
71 BASE_I18N_EXPORT HourClockType GetHourClockType(); | 86 BASE_I18N_EXPORT HourClockType GetHourClockType(); |
72 | 87 |
73 } // namespace base | 88 } // namespace base |
74 | 89 |
75 #endif // BASE_I18N_TIME_FORMATTING_H_ | 90 #endif // BASE_I18N_TIME_FORMATTING_H_ |
OLD | NEW |