license.bot | f003cfe | 2008-08-24 09:55:55 +0900 | [diff] [blame^] | 1 | // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. |
| 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 | #include "base/time_format.h" |
| 6 | |
| 7 | #include "base/logging.h" |
| 8 | #include "base/string_util.h" |
| 9 | #include "base/time.h" |
| 10 | #include "unicode/datefmt.h" |
| 11 | |
| 12 | namespace { |
| 13 | |
| 14 | std::wstring TimeFormat(const DateFormat* formatter, |
| 15 | const Time& time) { |
| 16 | DCHECK(formatter); |
| 17 | UnicodeString date_string; |
| 18 | |
| 19 | formatter->format(static_cast<UDate>(time.ToDoubleT() * 1000), date_string); |
tc@google.com | 4420f22 | 2008-08-23 04:25:23 +0900 | [diff] [blame] | 20 | std::wstring output; |
| 21 | bool success = UTF16ToWide(date_string.getBuffer(), date_string.length(), |
| 22 | &output); |
| 23 | DCHECK(success); |
| 24 | return output; |
tc@google.com | c7328d8 | 2008-08-20 07:35:29 +0900 | [diff] [blame] | 25 | } |
| 26 | |
| 27 | } |
| 28 | |
| 29 | namespace base { |
| 30 | |
| 31 | std::wstring TimeFormatTimeOfDay(const Time& time) { |
| 32 | // We can omit the locale parameter because the default should match |
| 33 | // Chrome's application locale. |
| 34 | scoped_ptr<DateFormat> formatter(DateFormat::createTimeInstance( |
| 35 | DateFormat::kShort)); |
| 36 | return TimeFormat(formatter.get(), time); |
| 37 | } |
| 38 | |
| 39 | std::wstring TimeFormatShortDate(const Time& time) { |
| 40 | scoped_ptr<DateFormat> formatter(DateFormat::createDateInstance( |
| 41 | DateFormat::kMedium)); |
| 42 | return TimeFormat(formatter.get(), time); |
| 43 | } |
| 44 | |
| 45 | std::wstring TimeFormatShortDateNumeric(const Time& time) { |
| 46 | scoped_ptr<DateFormat> formatter(DateFormat::createDateInstance( |
| 47 | DateFormat::kShort)); |
| 48 | return TimeFormat(formatter.get(), time); |
| 49 | } |
| 50 | |
| 51 | std::wstring TimeFormatShortDateAndTime(const Time& time) { |
| 52 | scoped_ptr<DateFormat> formatter(DateFormat::createDateTimeInstance( |
| 53 | DateFormat::kShort)); |
| 54 | return TimeFormat(formatter.get(), time); |
| 55 | } |
| 56 | |
| 57 | std::wstring TimeFormatFriendlyDateAndTime(const Time& time) { |
| 58 | scoped_ptr<DateFormat> formatter(DateFormat::createDateTimeInstance( |
| 59 | DateFormat::kFull)); |
| 60 | return TimeFormat(formatter.get(), time); |
| 61 | } |
| 62 | |
| 63 | std::wstring TimeFormatFriendlyDate(const Time& time) { |
| 64 | scoped_ptr<DateFormat> formatter(DateFormat::createDateInstance( |
| 65 | DateFormat::kFull)); |
| 66 | return TimeFormat(formatter.get(), time); |
| 67 | } |
| 68 | |
| 69 | } // namespace base |
license.bot | f003cfe | 2008-08-24 09:55:55 +0900 | [diff] [blame^] | 70 | |