Index: base/i18n/time_formatting.cc |
diff --git a/base/i18n/time_formatting.cc b/base/i18n/time_formatting.cc |
index fde255fa71e19d76a70fc570a0eb5c52c7b4cc8d..3f560ee55620ef1833fc07bc0092b614a7132a1d 100644 |
--- a/base/i18n/time_formatting.cc |
+++ b/base/i18n/time_formatting.cc |
@@ -12,6 +12,7 @@ |
#include "base/strings/utf_string_conversions.h" |
#include "base/time/time.h" |
#include "third_party/icu/source/i18n/unicode/datefmt.h" |
+#include "third_party/icu/source/i18n/unicode/dtitvfmt.h" |
#include "third_party/icu/source/i18n/unicode/dtptngen.h" |
#include "third_party/icu/source/i18n/unicode/fmtable.h" |
#include "third_party/icu/source/i18n/unicode/measfmt.h" |
@@ -81,6 +82,17 @@ UMeasureFormatWidth DurationWidthToMeasureWidth(DurationFormatWidth width) { |
return UMEASFMT_WIDTH_COUNT; |
} |
+const char* DateFormatToString(DateFormat format) { |
+ switch (format) { |
+ case DATE_FORMAT_YEAR_MONTH: |
+ return UDAT_YEAR_MONTH; |
+ case DATE_FORMAT_MONTH_WEEKDAY_DAY: |
+ return UDAT_MONTH_WEEKDAY_DAY; |
+ } |
+ NOTREACHED(); |
+ return UDAT_YEAR_MONTH_DAY; |
+} |
+ |
} // namespace |
string16 TimeFormatTimeOfDay(const Time& time) { |
@@ -141,6 +153,12 @@ string16 TimeFormatShortDateAndTimeWithTimeZone(const Time& time) { |
return TimeFormat(formatter.get(), time); |
} |
+string16 TimeFormatMonthAndYear(const Time& time) { |
+ icu::SimpleDateFormat formatter = |
+ CreateSimpleDateFormatter(DateFormatToString(DATE_FORMAT_YEAR_MONTH)); |
+ return TimeFormat(&formatter, time); |
+} |
+ |
string16 TimeFormatFriendlyDateAndTime(const Time& time) { |
std::unique_ptr<icu::DateFormat> formatter( |
icu::DateFormat::createDateTimeInstance(icu::DateFormat::kFull)); |
@@ -191,6 +209,25 @@ string16 TimeDurationFormatWithSeconds(const TimeDelta time, |
return base::string16(formatted.getBuffer(), formatted.length()); |
} |
+string16 DateIntervalFormat(const Time& begin_time, |
+ const Time& end_time, |
+ DateFormat format) { |
+ UErrorCode status = U_ZERO_ERROR; |
+ |
+ std::unique_ptr<icu::DateIntervalFormat> formatter( |
+ icu::DateIntervalFormat::createInstance(DateFormatToString(format), |
+ status)); |
+ |
+ icu::FieldPosition pos = 0; |
+ UDate start_date = static_cast<UDate>(begin_time.ToDoubleT() * 1000); |
+ UDate end_date = static_cast<UDate>(end_time.ToDoubleT() * 1000); |
+ icu::DateInterval interval(start_date, end_date); |
+ icu::UnicodeString formatted; |
+ formatter->format(&interval, formatted, pos, status); |
+ return string16(formatted.getBuffer(), |
+ static_cast<size_t>(formatted.length())); |
+} |
+ |
HourClockType GetHourClockType() { |
// TODO(satorux,jshin): Rework this with ures_getByKeyWithFallback() |
// once it becomes public. The short time format can be found at |