satorux@chromium.org | a0eb302 | 2011-04-14 14:08:02 +0900 | [diff] [blame] | 1 | // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
license.bot | f003cfe | 2008-08-24 09:55:55 +0900 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
tc@google.com | c7328d8 | 2008-08-20 07:35:29 +0900 | [diff] [blame] | 4 | |
| 5 | // Basic time formatting methods. These methods use the current locale |
| 6 | // formatting for displaying the time. |
| 7 | |
brettw@chromium.org | a52632f | 2009-10-10 03:20:30 +0900 | [diff] [blame] | 8 | #ifndef BASE_I18N_TIME_FORMATTING_H_ |
| 9 | #define BASE_I18N_TIME_FORMATTING_H_ |
thakis@chromium.org | 01d1452 | 2010-07-27 08:08:24 +0900 | [diff] [blame] | 10 | #pragma once |
tc@google.com | c7328d8 | 2008-08-20 07:35:29 +0900 | [diff] [blame] | 11 | |
rvargas@google.com | c4b016b | 2011-09-01 07:15:48 +0900 | [diff] [blame] | 12 | #include "base/i18n/base_i18n_export.h" |
avi@chromium.org | 20ac462 | 2010-12-23 00:08:08 +0900 | [diff] [blame] | 13 | #include "base/string16.h" |
tc@google.com | c7328d8 | 2008-08-20 07:35:29 +0900 | [diff] [blame] | 14 | |
tc@google.com | c7328d8 | 2008-08-20 07:35:29 +0900 | [diff] [blame] | 15 | namespace base { |
| 16 | |
dsh@google.com | 0f8dd26 | 2008-10-28 05:43:33 +0900 | [diff] [blame] | 17 | class Time; |
| 18 | |
satorux@chromium.org | a0eb302 | 2011-04-14 14:08:02 +0900 | [diff] [blame] | 19 | // Argument type used to specify the hour clock type. |
| 20 | enum HourClockType { |
| 21 | k12HourClock, // Uses 1-12. e.g., "3:07 PM" |
| 22 | k24HourClock, // Uses 0-23. e.g., "15:07" |
| 23 | }; |
| 24 | |
kinaba@google.com | 7f3f242 | 2011-05-30 20:45:43 +0900 | [diff] [blame] | 25 | // Argument type used to specify whether or not to include AM/PM sign. |
| 26 | enum AmPmClockType { |
| 27 | kDropAmPm, // Drops AM/PM sign. e.g., "3:07" |
| 28 | kKeepAmPm, // Keeps AM/PM sign. e.g., "3:07 PM" |
| 29 | }; |
| 30 | |
tc@google.com | c7328d8 | 2008-08-20 07:35:29 +0900 | [diff] [blame] | 31 | // Returns the time of day, e.g., "3:07 PM". |
rvargas@google.com | c4b016b | 2011-09-01 07:15:48 +0900 | [diff] [blame] | 32 | BASE_I18N_EXPORT string16 TimeFormatTimeOfDay(const Time& time); |
tc@google.com | c7328d8 | 2008-08-20 07:35:29 +0900 | [diff] [blame] | 33 | |
satorux@chromium.org | a0eb302 | 2011-04-14 14:08:02 +0900 | [diff] [blame] | 34 | // Returns the time of day in the specified hour clock type. e.g. |
kinaba@google.com | 7f3f242 | 2011-05-30 20:45:43 +0900 | [diff] [blame] | 35 | // "3:07 PM" (type == k12HourClock, ampm == kKeepAmPm). |
| 36 | // "3:07" (type == k12HourClock, ampm == kDropAmPm). |
satorux@chromium.org | a0eb302 | 2011-04-14 14:08:02 +0900 | [diff] [blame] | 37 | // "15:07" (type == k24HourClock). |
rvargas@google.com | c4b016b | 2011-09-01 07:15:48 +0900 | [diff] [blame] | 38 | BASE_I18N_EXPORT string16 TimeFormatTimeOfDayWithHourClockType( |
| 39 | const Time& time, |
| 40 | HourClockType type, |
| 41 | AmPmClockType ampm); |
satorux@chromium.org | a0eb302 | 2011-04-14 14:08:02 +0900 | [diff] [blame] | 42 | |
tc@google.com | c7328d8 | 2008-08-20 07:35:29 +0900 | [diff] [blame] | 43 | // Returns a shortened date, e.g. "Nov 7, 2007" |
rvargas@google.com | c4b016b | 2011-09-01 07:15:48 +0900 | [diff] [blame] | 44 | BASE_I18N_EXPORT string16 TimeFormatShortDate(const Time& time); |
tc@google.com | c7328d8 | 2008-08-20 07:35:29 +0900 | [diff] [blame] | 45 | |
| 46 | // Returns a numeric date such as 12/13/52. |
rvargas@google.com | c4b016b | 2011-09-01 07:15:48 +0900 | [diff] [blame] | 47 | BASE_I18N_EXPORT string16 TimeFormatShortDateNumeric(const Time& time); |
tc@google.com | c7328d8 | 2008-08-20 07:35:29 +0900 | [diff] [blame] | 48 | |
kinaba@google.com | 7f3f242 | 2011-05-30 20:45:43 +0900 | [diff] [blame] | 49 | // Returns a numeric date and time such as "12/13/52 2:44:30 PM". |
rvargas@google.com | c4b016b | 2011-09-01 07:15:48 +0900 | [diff] [blame] | 50 | BASE_I18N_EXPORT string16 TimeFormatShortDateAndTime(const Time& time); |
tc@google.com | c7328d8 | 2008-08-20 07:35:29 +0900 | [diff] [blame] | 51 | |
| 52 | // Formats a time in a friendly sentence format, e.g. |
| 53 | // "Monday, March 6, 2008 2:44:30 PM". |
rvargas@google.com | c4b016b | 2011-09-01 07:15:48 +0900 | [diff] [blame] | 54 | BASE_I18N_EXPORT string16 TimeFormatFriendlyDateAndTime(const Time& time); |
tc@google.com | c7328d8 | 2008-08-20 07:35:29 +0900 | [diff] [blame] | 55 | |
| 56 | // Formats a time in a friendly sentence format, e.g. |
| 57 | // "Monday, March 6, 2008". |
rvargas@google.com | c4b016b | 2011-09-01 07:15:48 +0900 | [diff] [blame] | 58 | BASE_I18N_EXPORT string16 TimeFormatFriendlyDate(const Time& time); |
tc@google.com | c7328d8 | 2008-08-20 07:35:29 +0900 | [diff] [blame] | 59 | |
satorux@chromium.org | a0eb302 | 2011-04-14 14:08:02 +0900 | [diff] [blame] | 60 | // Gets the hour clock type of the current locale. e.g. |
| 61 | // k12HourClock (en-US). |
| 62 | // k24HourClock (en-GB). |
rvargas@google.com | c4b016b | 2011-09-01 07:15:48 +0900 | [diff] [blame] | 63 | BASE_I18N_EXPORT HourClockType GetHourClockType(); |
satorux@chromium.org | a0eb302 | 2011-04-14 14:08:02 +0900 | [diff] [blame] | 64 | |
tc@google.com | c7328d8 | 2008-08-20 07:35:29 +0900 | [diff] [blame] | 65 | } // namespace base |
| 66 | |
brettw@chromium.org | a52632f | 2009-10-10 03:20:30 +0900 | [diff] [blame] | 67 | #endif // BASE_I18N_TIME_FORMATTING_H_ |