diff options
author | tc@google.com <tc@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2008-08-19 22:35:29 +0000 |
---|---|---|
committer | tc@google.com <tc@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2008-08-19 22:35:29 +0000 |
commit | 5cca3a55b3f1c25c5b3a19c3b42227aae34e4abf (patch) | |
tree | 01cd3db90399f7c24d3aea3593fd2d5feb35f106 /chrome/common/time_format.cc | |
parent | aac13f594195df51eb1e4e35ea2863659cb4de54 (diff) | |
download | chromium_src-5cca3a55b3f1c25c5b3a19c3b42227aae34e4abf.zip chromium_src-5cca3a55b3f1c25c5b3a19c3b42227aae34e4abf.tar.gz chromium_src-5cca3a55b3f1c25c5b3a19c3b42227aae34e4abf.tar.bz2 |
Move time formatters that only use ICU into base/time.*
This allows us to use the time formatters in, e.g., net
or webkit.
Remove CookieExpires since it's not used.
BUG=1164516
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@1063 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/common/time_format.cc')
-rw-r--r-- | chrome/common/time_format.cc | 68 |
1 files changed, 2 insertions, 66 deletions
diff --git a/chrome/common/time_format.cc b/chrome/common/time_format.cc index 1c4b576..e97316c 100644 --- a/chrome/common/time_format.cc +++ b/chrome/common/time_format.cc @@ -36,6 +36,7 @@ #include "base/singleton.h" #include "base/string_util.h" #include "base/time.h" +#include "base/time_format.h" #include "chrome/common/l10n_util.h" #include "chrome/common/stl_util-inl.h" #include "generated_resources.h" @@ -45,28 +46,6 @@ #include "unicode/plurrule.h" #include "unicode/smpdtfmt.h" -namespace { - -UDate TimeToUDate(const Time& time) { - return static_cast<UDate>(time.ToDoubleT() * 1000); -} - -std::wstring FormatTime(const DateFormat* formatter, const Time& time) { - DCHECK(formatter); - UnicodeString date_string; - formatter->format(TimeToUDate(time), date_string); - std::wstring formatted; - int capacity = date_string.length() + 1; - - UErrorCode error = U_ZERO_ERROR; - date_string.extract(static_cast<UChar*>(WriteInto(&formatted, capacity)), - capacity, error); - DCHECK(U_SUCCESS(error)); - return formatted; -} - -} // namespace - class TimeRemainingFormat { public: const std::vector<PluralFormat*>& formatter(bool short_version) { @@ -274,7 +253,7 @@ std::wstring TimeFormat::TimeRemainingShort(const TimeDelta& delta) { } // static -std::wstring TimeFormat::FriendlyDay( +std::wstring TimeFormat::RelativeDate( const Time& time, const Time* optional_midnight_today) { Time midnight_today = optional_midnight_today ? *optional_midnight_today : @@ -289,46 +268,3 @@ std::wstring TimeFormat::FriendlyDay( return std::wstring(); } - -std::wstring TimeFormat::TimeOfDay(const Time& time) { - // We can omit the locale parameter because the default should match - // Chrome's application locale. - scoped_ptr<DateFormat> formatter(DateFormat::createTimeInstance( - DateFormat::kShort)); - return FormatTime(formatter.get(), time); -} - -std::wstring TimeFormat::ShortDate(const Time& time) { - scoped_ptr<DateFormat> formatter(DateFormat::createDateInstance( - DateFormat::kMedium)); - return FormatTime(formatter.get(), time); -} - -std::wstring TimeFormat::ShortDateNumeric(const Time& time) { - scoped_ptr<DateFormat> formatter(DateFormat::createDateInstance( - DateFormat::kShort)); - return FormatTime(formatter.get(), time); -} - -std::wstring TimeFormat::FriendlyDateAndTime(const Time& time) { - scoped_ptr<DateFormat> formatter(DateFormat::createDateTimeInstance( - DateFormat::kFull)); - return FormatTime(formatter.get(), time); -} - -std::wstring TimeFormat::FriendlyDate(const Time& time) { - scoped_ptr<DateFormat> formatter(DateFormat::createDateInstance( - DateFormat::kFull)); - return FormatTime(formatter.get(), time); -} - -std::wstring TimeFormat::CookieExpires(const Time& time) { - UErrorCode error = U_ZERO_ERROR; - SimpleDateFormat simple_date_formatter("EEE, dd-MMM-yyyy HH:mm:ss 'GMT'", - Locale::getEnglish(), error); - if (U_FAILURE(error)) - return std::wstring(); - - simple_date_formatter.adoptTimeZone(TimeZone::getGMT()->clone()); - return FormatTime(&simple_date_formatter, time); -} |