Commit b6174e14 authored by Peter Kasting's avatar Peter Kasting Committed by Commit Bot

More consistent use of base::Time constants.

Add kMinutesPerHour, which was missing, and use that and the other
existing constants to replace some raw magic numbers.

Bug: none
Change-Id: Ia3460090d817d4e9c93f629a4033bef8d476c3a9
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2293286
Commit-Queue: Nico Weber <thakis@chromium.org>
Reviewed-by: default avatarNico Weber <thakis@chromium.org>
Auto-Submit: Peter Kasting <pkasting@chromium.org>
Cr-Commit-Position: refs/heads/master@{#787578}
parent 2820b750
......@@ -430,15 +430,19 @@ class TimeBase {
public:
static constexpr int64_t kHoursPerDay = 24;
static constexpr int64_t kSecondsPerMinute = 60;
static constexpr int64_t kSecondsPerHour = 60 * kSecondsPerMinute;
static constexpr int64_t kMinutesPerHour = 60;
static constexpr int64_t kSecondsPerHour =
kSecondsPerMinute * kMinutesPerHour;
static constexpr int64_t kMillisecondsPerSecond = 1000;
static constexpr int64_t kMillisecondsPerDay =
kMillisecondsPerSecond * 60 * 60 * kHoursPerDay;
kMillisecondsPerSecond * kSecondsPerHour * kHoursPerDay;
static constexpr int64_t kMicrosecondsPerMillisecond = 1000;
static constexpr int64_t kMicrosecondsPerSecond =
kMicrosecondsPerMillisecond * kMillisecondsPerSecond;
static constexpr int64_t kMicrosecondsPerMinute = kMicrosecondsPerSecond * 60;
static constexpr int64_t kMicrosecondsPerHour = kMicrosecondsPerMinute * 60;
static constexpr int64_t kMicrosecondsPerMinute =
kMicrosecondsPerSecond * kSecondsPerMinute;
static constexpr int64_t kMicrosecondsPerHour =
kMicrosecondsPerMinute * kMinutesPerHour;
static constexpr int64_t kMicrosecondsPerDay =
kMicrosecondsPerHour * kHoursPerDay;
static constexpr int64_t kMicrosecondsPerWeek = kMicrosecondsPerDay * 7;
......
......@@ -28,6 +28,7 @@
#include <algorithm>
#include "base/auto_reset.h"
#include "base/time/time.h"
#include "third_party/blink/public/platform/task_type.h"
#include "third_party/blink/renderer/bindings/core/v8/script_event_listener.h"
#include "third_party/blink/renderer/core/dom/document.h"
......@@ -345,16 +346,20 @@ SMILTime SVGSMILElement::ParseOffsetValue(const String& data) {
bool ok;
double result = 0;
String parse = data.StripWhiteSpace();
if (parse.EndsWith('h'))
result = parse.Left(parse.length() - 1).ToDouble(&ok) * 60 * 60;
else if (parse.EndsWith("min"))
result = parse.Left(parse.length() - 3).ToDouble(&ok) * 60;
else if (parse.EndsWith("ms"))
result = parse.Left(parse.length() - 2).ToDouble(&ok) / 1000;
else if (parse.EndsWith('s'))
if (parse.EndsWith('h')) {
result = parse.Left(parse.length() - 1).ToDouble(&ok) *
base::Time::kSecondsPerHour;
} else if (parse.EndsWith("min")) {
result = parse.Left(parse.length() - 3).ToDouble(&ok) *
base::Time::kSecondsPerMinute;
} else if (parse.EndsWith("ms")) {
result = parse.Left(parse.length() - 2).ToDouble(&ok) /
base::Time::kMillisecondsPerSecond;
} else if (parse.EndsWith('s')) {
result = parse.Left(parse.length() - 1).ToDouble(&ok);
else
} else {
result = parse.ToDouble(&ok);
}
if (!ok)
return SMILTime::Unresolved();
return SMILTime::FromSecondsD(result);
......
......@@ -88,7 +88,9 @@ base::string16 TimeFormat::DetailedWithMonthAndYear(
const int seconds = static_cast<int>((delta + half_second).InSeconds());
formatter->Format(Formatter::UNIT_SEC, seconds, &time_string);
} else if (delta < one_hour - (cutoff < 60 ? half_minute : half_second)) {
} else if (delta < one_hour - (cutoff < base::Time::kMinutesPerHour
? half_minute
: half_second)) {
// Anything up to 59.5 minutes (respectively 59:59.500 when |cutoff| permits
// two-value output) is formatted as minutes (respectively minutes and
// seconds).
......@@ -97,13 +99,15 @@ base::string16 TimeFormat::DetailedWithMonthAndYear(
formatter->Format(Formatter::UNIT_MIN, minutes, &time_string);
} else {
const int minutes = (delta + half_second).InMinutes();
const int seconds = static_cast<int>(
(delta + half_second).InSeconds() % 60);
const int seconds = static_cast<int>((delta + half_second).InSeconds() %
base::Time::kSecondsPerMinute);
formatter->Format(Formatter::TWO_UNITS_MIN_SEC,
minutes, seconds, &time_string);
}
} else if (delta < one_day - (cutoff < 24 ? half_hour : half_minute)) {
} else if (delta < one_day - (cutoff < base::Time::kHoursPerDay
? half_hour
: half_minute)) {
// Anything up to 23.5 hours (respectively 23:59:30.000 when |cutoff|
// permits two-value output) is formatted as hours (respectively hours and
// minutes).
......@@ -112,7 +116,8 @@ base::string16 TimeFormat::DetailedWithMonthAndYear(
formatter->Format(Formatter::UNIT_HOUR, hours, &time_string);
} else {
const int hours = (delta + half_minute).InHours();
const int minutes = (delta + half_minute).InMinutes() % 60;
const int minutes =
(delta + half_minute).InMinutes() % base::Time::kMinutesPerHour;
formatter->Format(Formatter::TWO_UNITS_HOUR_MIN,
hours, minutes, &time_string);
}
......@@ -123,7 +128,8 @@ base::string16 TimeFormat::DetailedWithMonthAndYear(
formatter->Format(Formatter::UNIT_DAY, days, &time_string);
} else {
const int days = (delta + half_hour).InDays();
const int hours = (delta + half_hour).InHours() % 24;
const int hours =
(delta + half_hour).InHours() % base::Time::kHoursPerDay;
formatter->Format(Formatter::TWO_UNITS_DAY_HOUR,
days, hours, &time_string);
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment