Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(263)

Unified Diff: ui/base/l10n/time_format.cc

Issue 2845693002: Add month and year to time_format. (Closed)
Patch Set: Address comments Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « ui/base/l10n/time_format.h ('k') | ui/base/l10n/time_format_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ui/base/l10n/time_format.cc
diff --git a/ui/base/l10n/time_format.cc b/ui/base/l10n/time_format.cc
index 772564b9d31794c130539efa7d84bbcf1f8d327f..2ac75b0686e39fc0f37549ebfa43cd2664ae4133 100644
--- a/ui/base/l10n/time_format.cc
+++ b/ui/base/l10n/time_format.cc
@@ -32,11 +32,28 @@ base::string16 TimeFormat::Simple(TimeFormat::Format format,
return Detailed(format, length, 0, delta);
}
+base::string16 TimeFormat::SimpleWithMonthAndYear(TimeFormat::Format format,
+ TimeFormat::Length length,
+ const base::TimeDelta& delta,
+ bool with_month_and_year) {
+ return DetailedWithMonthAndYear(format, length, 0, delta,
+ with_month_and_year);
+}
+
// static
base::string16 TimeFormat::Detailed(TimeFormat::Format format,
TimeFormat::Length length,
int cutoff,
const base::TimeDelta& delta) {
+ return DetailedWithMonthAndYear(format, length, cutoff, delta, false);
+}
+
+base::string16 TimeFormat::DetailedWithMonthAndYear(
+ TimeFormat::Format format,
+ TimeFormat::Length length,
+ int cutoff,
+ const base::TimeDelta& delta,
+ bool with_month_and_year) {
if (delta < TimeDelta::FromSeconds(0)) {
NOTREACHED() << "Negative duration";
return base::string16();
@@ -49,6 +66,13 @@ base::string16 TimeFormat::Detailed(TimeFormat::Format format,
const TimeDelta one_minute(TimeDelta::FromMinutes(1));
const TimeDelta one_hour(TimeDelta::FromHours(1));
const TimeDelta one_day(TimeDelta::FromDays(1));
+
+ // An average month is a twelfth of a year.
+ const TimeDelta one_month(TimeDelta::FromDays(365) / 12);
+
+ // Simplify one year to be 365 days.
+ const TimeDelta one_year(TimeDelta::FromDays(365));
+
const TimeDelta half_second(TimeDelta::FromMilliseconds(500));
const TimeDelta half_minute(TimeDelta::FromSeconds(30));
const TimeDelta half_hour(TimeDelta::FromMinutes(30));
@@ -91,8 +115,7 @@ base::string16 TimeFormat::Detailed(TimeFormat::Format format,
formatter->Format(Formatter::TWO_UNITS_HOUR_MIN,
hours, minutes, &time_string);
}
-
- } else {
+ } else if (!with_month_and_year || delta < one_month) {
// Anything bigger is formatted as days (respectively days and hours).
if (delta >= cutoff * one_day - half_hour) {
const int days = (delta + half_day).InDays();
@@ -103,6 +126,15 @@ base::string16 TimeFormat::Detailed(TimeFormat::Format format,
formatter->Format(Formatter::TWO_UNITS_DAY_HOUR,
days, hours, &time_string);
}
+ } else if (delta < one_year) {
+ DCHECK(with_month_and_year);
+ int month = delta / one_month;
+ DCHECK(month >= 1 && month <= 12);
+ formatter->Format(Formatter::UNIT_MONTH, month, &time_string);
+ } else {
+ DCHECK(with_month_and_year);
+ int year = delta / one_year;
+ formatter->Format(Formatter::UNIT_YEAR, year, &time_string);
}
const int capacity = time_string.length() + 1;
« no previous file with comments | « ui/base/l10n/time_format.h ('k') | ui/base/l10n/time_format_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698