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

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

Issue 143633003: Fix rounding of time interval strings (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 11 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 | « no previous file | ui/base/l10n/time_format_unittest.cc » ('j') | ui/base/l10n/time_format_unittest.cc » ('J')
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 f3b16a3f969ac1115b642550d5146660ce1b7ea3..2d2c43bdbfe65e620965e12e061d203917ccdd25 100644
--- a/ui/base/l10n/time_format.cc
+++ b/ui/base/l10n/time_format.cc
@@ -294,27 +294,29 @@ base::string16 FormatTimeImpl(const TimeDelta& delta, FormatType format_type) {
UErrorCode error = U_ZERO_ERROR;
icu::UnicodeString time_string;
+ const int64 d2i = delta.ToInternalValue();
bartfab (slow) 2014/01/28 15:16:46 Nit: Wherever possible, we avoid abbreviations. |d
+
// Less than a minute gets "X seconds left"
- if (delta.ToInternalValue() < Time::kMicrosecondsPerMinute) {
- number = static_cast<int>(delta.ToInternalValue() /
+ if (d2i < Time::kMicrosecondsPerMinute-Time::kMicrosecondsPerSecond/2) {
bartfab (slow) 2014/01/28 15:16:46 1) Here and elsewhere in the file: Add spaces arou
+ number = static_cast<int>((d2i+Time::kMicrosecondsPerSecond/2) /
Time::kMicrosecondsPerSecond);
time_string = formatters[0]->format(number, error);
// Less than 1 hour gets "X minutes left".
- } else if (delta.ToInternalValue() < Time::kMicrosecondsPerHour) {
- number = static_cast<int>(delta.ToInternalValue() /
+ } else if (d2i < Time::kMicrosecondsPerHour-Time::kMicrosecondsPerMinute/2) {
+ number = static_cast<int>((d2i+Time::kMicrosecondsPerMinute/2) /
Time::kMicrosecondsPerMinute);
time_string = formatters[1]->format(number, error);
// Less than 1 day remaining gets "X hours left"
- } else if (delta.ToInternalValue() < Time::kMicrosecondsPerDay) {
- number = static_cast<int>(delta.ToInternalValue() /
+ } else if (d2i < Time::kMicrosecondsPerDay-Time::kMicrosecondsPerHour/2) {
+ number = static_cast<int>((d2i+Time::kMicrosecondsPerHour/2) /
Time::kMicrosecondsPerHour);
time_string = formatters[2]->format(number, error);
// Anything bigger gets "X days left"
} else {
- number = static_cast<int>(delta.ToInternalValue() /
+ number = static_cast<int>((d2i+Time::kMicrosecondsPerDay/2) /
Time::kMicrosecondsPerDay);
time_string = formatters[3]->format(number, error);
}
« no previous file with comments | « no previous file | ui/base/l10n/time_format_unittest.cc » ('j') | ui/base/l10n/time_format_unittest.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698