summaryrefslogtreecommitdiffstats
path: root/chrome/common
diff options
context:
space:
mode:
Diffstat (limited to 'chrome/common')
-rw-r--r--chrome/common/time_format.cc68
-rw-r--r--chrome/common/time_format.h27
-rw-r--r--chrome/common/time_format_unittest.cc28
3 files changed, 9 insertions, 114 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);
-}
diff --git a/chrome/common/time_format.h b/chrome/common/time_format.h
index d51f844..61e1d68 100644
--- a/chrome/common/time_format.h
+++ b/chrome/common/time_format.h
@@ -63,31 +63,8 @@ class TimeFormat {
// If NULL, the current day's midnight will be retrieved, which can be
// slow. If many items are being processed, it is best to get the current
// time once at the beginning and pass it for each computation.
- static std::wstring FriendlyDay(const Time& time,
- const Time* optional_midnight_today);
-
- // Returns the time of day, e.g., "3:07 PM".
- static std::wstring TimeOfDay(const Time& time);
-
- // Returns a shortened date, e.g. "Nov 7, 2007"
- static std::wstring ShortDate(const Time& time);
-
- // Returns a numeric date such as 12/13/52.
- static std::wstring ShortDateNumeric(const Time& time);
-
- // Formats a time in a friendly sentence format, e.g.
- // "Monday, March 6, 2008 2:44:30 PM".
- static std::wstring FriendlyDateAndTime(const Time& time);
-
- // Formats a time in a friendly sentence format, e.g.
- // "Monday, March 6, 2008".
- static std::wstring FriendlyDate(const Time& time);
-
- // Returns a time format used in a cookie expires attribute, e.g.
- // "Wed, 25-Apr-2007 21:02:13 GMT"
- // Its only legal time zone is GMT, and it can be parsed by
- // CookieMonster::ParseCookieTime().
- static std::wstring CookieExpires(const Time& time);
+ static std::wstring RelativeDate(const Time& time,
+ const Time* optional_midnight_today);
};
#endif // CHROME_COMMON_TIME_FORMAT_H__
diff --git a/chrome/common/time_format_unittest.cc b/chrome/common/time_format_unittest.cc
index e79ce04..dd6778a 100644
--- a/chrome/common/time_format_unittest.cc
+++ b/chrome/common/time_format_unittest.cc
@@ -35,21 +35,21 @@
#include "chrome/common/time_format.h"
#include "testing/gtest/include/gtest/gtest.h"
-TEST(TimeFormat, FriendlyDay) {
+TEST(TimeFormat, RelativeDate) {
Time now = Time::Now();
- std::wstring today_str = TimeFormat::FriendlyDay(now, NULL);
+ std::wstring today_str = TimeFormat::RelativeDate(now, NULL);
EXPECT_EQ(L"Today", today_str);
Time yesterday = now - TimeDelta::FromDays(1);
- std::wstring yesterday_str = TimeFormat::FriendlyDay(yesterday, NULL);
+ std::wstring yesterday_str = TimeFormat::RelativeDate(yesterday, NULL);
EXPECT_EQ(L"Yesterday", yesterday_str);
Time two_days_ago = now - TimeDelta::FromDays(2);
- std::wstring two_days_ago_str = TimeFormat::FriendlyDay(two_days_ago, NULL);
+ std::wstring two_days_ago_str = TimeFormat::RelativeDate(two_days_ago, NULL);
EXPECT_TRUE(two_days_ago_str.empty());
Time a_week_ago = now - TimeDelta::FromDays(7);
- std::wstring a_week_ago_str = TimeFormat::FriendlyDay(a_week_ago, NULL);
+ std::wstring a_week_ago_str = TimeFormat::RelativeDate(a_week_ago, NULL);
EXPECT_TRUE(a_week_ago_str.empty());
}
@@ -89,21 +89,3 @@ TEST(TimeFormat, RemainingTime) {
TestRemainingTime(three_days, L"3 days", L"3 days left");
TestRemainingTime(three_days + four_hours, L"3 days", L"3 days left");
}
-
-#if 0
-TEST(TimeFormat, FriendlyDateAndTime) {
- Time::Exploded exploded;
- exploded.year = 2008;
- exploded.month = 3;
- exploded.day_of_week = 1;
- exploded.day_of_month = 31;
- exploded.hour = 14;
- exploded.minute = 44;
- exploded.second = 30;
- exploded.millisecond = 549;
- Time t = Time::FromLocalExploded(exploded);
-
- std::wstring normal_time = L"Monday, March 31, 2008 2:44:30 PM";
- EXPECT_EQ(normal_time, TimeFormat::FriendlyDateAndTime(t));
-}
-#endif