summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authortc@google.com <tc@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2008-08-19 22:35:29 +0000
committertc@google.com <tc@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2008-08-19 22:35:29 +0000
commit5cca3a55b3f1c25c5b3a19c3b42227aae34e4abf (patch)
tree01cd3db90399f7c24d3aea3593fd2d5feb35f106
parentaac13f594195df51eb1e4e35ea2863659cb4de54 (diff)
downloadchromium_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
-rw-r--r--base/SConscript1
-rw-r--r--base/build/base.vcproj8
-rw-r--r--base/time_format.cc90
-rw-r--r--base/time_format.h65
-rw-r--r--chrome/browser/download_tab_view.cc5
-rw-r--r--chrome/browser/history_view.cc13
-rw-r--r--chrome/browser/page_info_window.cc4
-rw-r--r--chrome/browser/printing/win_printing_context.cc6
-rw-r--r--chrome/browser/views/options/cookies_view.cc6
-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
-rw-r--r--net/base/net_util.cc26
13 files changed, 195 insertions, 152 deletions
diff --git a/base/SConscript b/base/SConscript
index 4a06cbd..190fdfd 100644
--- a/base/SConscript
+++ b/base/SConscript
@@ -83,6 +83,7 @@ input_files = [
'string_util.cc',
'string_util_icu.cc',
'time.cc',
+ 'time_format.cc',
'timer.cc',
'tracked.cc',
'tracked_objects.cc',
diff --git a/base/build/base.vcproj b/base/build/base.vcproj
index 7fc1bfb..e4c00d1 100644
--- a/base/build/base.vcproj
+++ b/base/build/base.vcproj
@@ -710,6 +710,14 @@
>
</File>
<File
+ RelativePath="..\time_format.cc"
+ >
+ </File>
+ <File
+ RelativePath="..\time_format.h"
+ >
+ </File>
+ <File
RelativePath="..\timer.cc"
>
</File>
diff --git a/base/time_format.cc b/base/time_format.cc
new file mode 100644
index 0000000..8d2d39e
--- /dev/null
+++ b/base/time_format.cc
@@ -0,0 +1,90 @@
+// Copyright 2008, Google Inc.
+// All rights reserved.
+//
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are
+// met:
+//
+// * Redistributions of source code must retain the above copyright
+// notice, this list of conditions and the following disclaimer.
+// * Redistributions in binary form must reproduce the above
+// copyright notice, this list of conditions and the following disclaimer
+// in the documentation and/or other materials provided with the
+// distribution.
+// * Neither the name of Google Inc. nor the names of its
+// contributors may be used to endorse or promote products derived from
+// this software without specific prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+#include "base/time_format.h"
+
+#include "base/logging.h"
+#include "base/string_util.h"
+#include "base/time.h"
+#include "unicode/datefmt.h"
+
+namespace {
+
+std::wstring TimeFormat(const DateFormat* formatter,
+ const Time& time) {
+ DCHECK(formatter);
+ UnicodeString date_string;
+
+ formatter->format(static_cast<UDate>(time.ToDoubleT() * 1000), date_string);
+ return UTF16ToWide(date_string.getTerminatedBuffer());
+}
+
+}
+
+namespace base {
+
+std::wstring TimeFormatTimeOfDay(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 TimeFormat(formatter.get(), time);
+}
+
+std::wstring TimeFormatShortDate(const Time& time) {
+ scoped_ptr<DateFormat> formatter(DateFormat::createDateInstance(
+ DateFormat::kMedium));
+ return TimeFormat(formatter.get(), time);
+}
+
+std::wstring TimeFormatShortDateNumeric(const Time& time) {
+ scoped_ptr<DateFormat> formatter(DateFormat::createDateInstance(
+ DateFormat::kShort));
+ return TimeFormat(formatter.get(), time);
+}
+
+std::wstring TimeFormatShortDateAndTime(const Time& time) {
+ scoped_ptr<DateFormat> formatter(DateFormat::createDateTimeInstance(
+ DateFormat::kShort));
+ return TimeFormat(formatter.get(), time);
+}
+
+std::wstring TimeFormatFriendlyDateAndTime(const Time& time) {
+ scoped_ptr<DateFormat> formatter(DateFormat::createDateTimeInstance(
+ DateFormat::kFull));
+ return TimeFormat(formatter.get(), time);
+}
+
+std::wstring TimeFormatFriendlyDate(const Time& time) {
+ scoped_ptr<DateFormat> formatter(DateFormat::createDateInstance(
+ DateFormat::kFull));
+ return TimeFormat(formatter.get(), time);
+}
+
+} // namespace base
diff --git a/base/time_format.h b/base/time_format.h
new file mode 100644
index 0000000..477ef0a
--- /dev/null
+++ b/base/time_format.h
@@ -0,0 +1,65 @@
+// Copyright 2008, Google Inc.
+// All rights reserved.
+//
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are
+// met:
+//
+// * Redistributions of source code must retain the above copyright
+// notice, this list of conditions and the following disclaimer.
+// * Redistributions in binary form must reproduce the above
+// copyright notice, this list of conditions and the following disclaimer
+// in the documentation and/or other materials provided with the
+// distribution.
+// * Neither the name of Google Inc. nor the names of its
+// contributors may be used to endorse or promote products derived from
+// this software without specific prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+// Basic time formatting methods. These methods use the current locale
+// formatting for displaying the time.
+
+#ifndef BASE_TIME_FORMAT_H_
+#define BASE_TIME_FORMAT_H_
+
+#include <string>
+
+class Time;
+
+namespace base {
+
+// Returns the time of day, e.g., "3:07 PM".
+std::wstring TimeFormatTimeOfDay(const Time& time);
+
+// Returns a shortened date, e.g. "Nov 7, 2007"
+std::wstring TimeFormatShortDate(const Time& time);
+
+// Returns a numeric date such as 12/13/52.
+std::wstring TimeFormatShortDateNumeric(const Time& time);
+
+// Formats a time in a friendly sentence format, e.g.
+// "Monday, March 6, 2008 2:44:30 PM".
+std::wstring TimeFormatShortDateAndTime(const Time& time);
+
+// Formats a time in a friendly sentence format, e.g.
+// "Monday, March 6, 2008 2:44:30 PM".
+std::wstring TimeFormatFriendlyDateAndTime(const Time& time);
+
+// Formats a time in a friendly sentence format, e.g.
+// "Monday, March 6, 2008".
+std::wstring TimeFormatFriendlyDate(const Time& time);
+
+} // namespace base
+
+#endif // BASE_TIME_FORMAT_H_
diff --git a/chrome/browser/download_tab_view.cc b/chrome/browser/download_tab_view.cc
index d675833..f2424a0 100644
--- a/chrome/browser/download_tab_view.cc
+++ b/chrome/browser/download_tab_view.cc
@@ -37,6 +37,7 @@
#include "base/file_util.h"
#include "base/string_util.h"
#include "base/task.h"
+#include "base/time_format.h"
#include "base/timer.h"
#include "chrome/app/theme/theme_resources.h"
#include "chrome/browser/browser_process.h"
@@ -252,13 +253,13 @@ void DownloadItemTabView::LayoutDate() {
CSize since_size;
- since_->SetText(TimeFormat::FriendlyDay(model_->start_time(), NULL));
+ since_->SetText(TimeFormat::RelativeDate(model_->start_time(), NULL));
since_->GetPreferredSize(&since_size);
since_->SetBounds(kLeftMargin, kIconOffset, kDateSize, since_size.cy);
since_->SetVisible(true);
CSize date_size;
- date_->SetText(TimeFormat::ShortDate(model_->start_time()));
+ date_->SetText(base::TimeFormatShortDate(model_->start_time()));
date_->GetPreferredSize(&date_size);
date_->SetBounds(kLeftMargin, since_size.cy + kVerticalPadding + kIconOffset,
kDateSize, date_size.cy);
diff --git a/chrome/browser/history_view.cc b/chrome/browser/history_view.cc
index 7af3135..8cdc7a4 100644
--- a/chrome/browser/history_view.cc
+++ b/chrome/browser/history_view.cc
@@ -30,6 +30,7 @@
#include "chrome/browser/history_view.h"
#include "base/string_util.h"
+#include "base/time_format.h"
#include "base/word_iterator.h"
#include "chrome/browser/browsing_data_remover.h"
#include "chrome/browser/drag_utils.h"
@@ -475,9 +476,9 @@ void HistoryItemRenderer::Layout() {
time_label_->SetText(std::wstring());
} else if (show_full_) {
time_x = 0;
- time_label_->SetText(TimeFormat::ShortDate(visit_time));
+ time_label_->SetText(base::TimeFormatShortDate(visit_time));
} else {
- time_label_->SetText(TimeFormat::TimeOfDay(visit_time));
+ time_label_->SetText(base::TimeFormatTimeOfDay(visit_time));
}
time_label_->GetPreferredSize(&time_size);
@@ -983,14 +984,14 @@ void HistoryView::Paint(ChromeCanvas* canvas) {
DCHECK(visit_time.ToInternalValue() > 0);
// If it's the first day, then it has a special presentation.
- std::wstring date_str = TimeFormat::FriendlyDay(visit_time,
- &midnight_today);
+ std::wstring date_str = TimeFormat::RelativeDate(visit_time,
+ &midnight_today);
if (date_str.empty()) {
- date_str = TimeFormat::FriendlyDate(visit_time);
+ date_str = base::TimeFormatFriendlyDate(visit_time);
} else {
date_str = l10n_util::GetStringF(
IDS_HISTORY_DATE_WITH_RELATIVE_TIME,
- date_str, TimeFormat::FriendlyDate(visit_time));
+ date_str, base::TimeFormatFriendlyDate(visit_time));
}
// Draw date
diff --git a/chrome/browser/page_info_window.cc b/chrome/browser/page_info_window.cc
index b27f2ba..6a4bd25 100644
--- a/chrome/browser/page_info_window.cc
+++ b/chrome/browser/page_info_window.cc
@@ -33,6 +33,7 @@
#pragma comment(lib, "cryptui.lib")
#include "base/string_util.h"
+#include "base/time_format.h"
#include "chrome/app/locales/locale_settings.h"
#include "chrome/app/theme/theme_resources.h"
#include "chrome/browser/browser_process.h"
@@ -46,7 +47,6 @@
#include "chrome/common/pref_names.h"
#include "chrome/common/pref_service.h"
#include "chrome/common/resource_bundle.h"
-#include "chrome/common/time_format.h"
#include "chrome/common/win_util.h"
#include "chrome/views/background.h"
#include "chrome/views/grid_layout.h"
@@ -445,7 +445,7 @@ void SecurityTabView::OnGotVisitCountToHost(HistoryService::Handle handle,
l10n_util::GetString(IDS_PAGE_INFO_SECURITY_TAB_PERSONAL_HISTORY_TITLE),
true, std::wstring(),
l10n_util::GetStringF(IDS_PAGE_INFO_SECURITY_TAB_VISITED_BEFORE_TODAY,
- TimeFormat::ShortDate(first_visit)));
+ base::TimeFormatShortDate(first_visit)));
}
Layout();
SchedulePaint();
diff --git a/chrome/browser/printing/win_printing_context.cc b/chrome/browser/printing/win_printing_context.cc
index 1e3da12..cb275a8 100644
--- a/chrome/browser/printing/win_printing_context.cc
+++ b/chrome/browser/printing/win_printing_context.cc
@@ -33,10 +33,10 @@
#include "base/file_util.h"
#include "base/gfx/platform_device_win.h"
+#include "base/time_format.h"
#include "chrome/browser/browser_process.h"
#include "chrome/browser/printing/print_job_manager.h"
#include "chrome/common/gfx/emf.h"
-#include "chrome/common/time_format.h"
namespace {
@@ -304,9 +304,9 @@ PrintingContext::Result PrintingContext::NewDocument(
// Create a filename.
std::wstring filename;
Time now(Time::Now());
- filename = TimeFormat::ShortDateNumeric(now);
+ filename = base::TimeFormatShortDateNumeric(now);
filename += L"_";
- filename += TimeFormat::TimeOfDay(now);
+ filename += base::TimeFormatTimeOfDay(now);
filename += L"_";
filename += document_name;
filename += L"_";
diff --git a/chrome/browser/views/options/cookies_view.cc b/chrome/browser/views/options/cookies_view.cc
index 8d93fed..142a62b8 100644
--- a/chrome/browser/views/options/cookies_view.cc
+++ b/chrome/browser/views/options/cookies_view.cc
@@ -32,6 +32,7 @@
#include "chrome/browser/views/options/cookies_view.h"
#include "base/string_util.h"
+#include "base/time_format.h"
#include "chrome/app/locales/locale_settings.h"
#include "chrome/app/theme/theme_resources.h"
#include "chrome/browser/standard_layout.h"
@@ -39,7 +40,6 @@
#include "chrome/common/gfx/color_utils.h"
#include "chrome/common/l10n_util.h"
#include "chrome/common/resource_bundle.h"
-#include "chrome/common/time_format.h"
#include "chrome/common/win_util.h"
#include "chrome/views/border.h"
#include "chrome/views/grid_layout.h"
@@ -403,11 +403,11 @@ void CookieInfoView::SetCookie(
domain_value_field_->SetText(UTF8ToWide(domain));
path_value_field_->SetText(UTF8ToWide(cookie.Path()));
created_value_field_->SetText(
- TimeFormat::FriendlyDateAndTime(cookie.CreationDate()));
+ base::TimeFormatFriendlyDateAndTime(cookie.CreationDate()));
if (cookie.DoesExpire()) {
expires_value_field_->SetText(
- TimeFormat::FriendlyDateAndTime(cookie.ExpiryDate()));
+ base::TimeFormatFriendlyDateAndTime(cookie.ExpiryDate()));
} else {
// TODO(deanm) need a string that the average user can understand
// "When you quit or restart your browser" ?
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
diff --git a/net/base/net_util.cc b/net/base/net_util.cc
index efcdc66..fe26d14 100644
--- a/net/base/net_util.cc
+++ b/net/base/net_util.cc
@@ -50,6 +50,7 @@
#include "base/string_util.h"
#include "base/sys_string_conversions.h"
#include "base/time.h"
+#include "base/time_format.h"
#include "googleurl/src/gurl.h"
#include "googleurl/src/url_canon.h"
#include "googleurl/src/url_parse.h"
@@ -640,26 +641,6 @@ void IDNToUnicodeOneComponent(const wchar_t* comp,
(*out)[host_begin_in_output + i] = comp[i];
}
-// Convert a FILETIME to a localized string. |filetime| may be NULL.
-// TODO(tc): Remove this once bug 1164516 is fixed.
-std::wstring LocalizedDateTime(const FILETIME* filetime) {
- if (!filetime)
- return std::wstring();
-
- Time time = Time::FromFileTime(*filetime);
- scoped_ptr<DateFormat> formatter(DateFormat::createDateTimeInstance(
- DateFormat::kShort));
- UnicodeString date_string;
- formatter->format(static_cast<UDate>(time.ToDoubleT() * 1000), 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);
- return formatted;
-}
-
} // namespace
namespace net {
@@ -912,8 +893,9 @@ std::string GetDirectoryListingEntry(const std::string& name,
result.append(",");
- string_escape::JavascriptDoubleQuote(
- LocalizedDateTime(modified), true, &result);
+ Time time(Time::FromFileTime(*modified));
+ string_escape::JavascriptDoubleQuote(base::TimeFormatShortDateAndTime(time),
+ true, &result);
result.append(");</script>\n");