diff options
author | apavlov@chromium.org <apavlov@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-03-04 10:58:15 +0000 |
---|---|---|
committer | apavlov@chromium.org <apavlov@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-03-04 10:58:15 +0000 |
commit | 6857bbab378b7ae7f61399ff4af03ca2fcbe6c60 (patch) | |
tree | 0407945f372c0764e77297987de13832e5812aa9 /base/time | |
parent | 0fb050ca8edb8f9d5ec3c703784281796c107407 (diff) | |
download | chromium_src-6857bbab378b7ae7f61399ff4af03ca2fcbe6c60.zip chromium_src-6857bbab378b7ae7f61399ff4af03ca2fcbe6c60.tar.gz chromium_src-6857bbab378b7ae7f61399ff4af03ca2fcbe6c60.tar.bz2 |
Revert of Reland "Add base::TimeDelta::Max()" (https://codereview.chromium.org/183763011/)
Reason for revert:
http/tests/media/video-cookie.html is asserting on debug bots
Original issue's description:
> Reland "Add base::TimeDelta::Max()"
>
> Media was exposing max timedeltas to JSON, which wasn't working with
> infinity.
>
> R=scherkus@chromium.org
> TBR=ajwong@chromium.org,jar@chromium.org,jamesr@chomium.org,acolwell@chromium.org,nick@chromium.org
> BUG=None
>
> Committed: https://src.chromium.org/viewvc/chrome?view=rev&revision=254717
TBR=ajwong@chromium.org,jar@chromium.org,scherkus@chromium.org,jamesr@chomium.org,acolwell@chromium.org,nick@chromium.org,gavinp@chromium.org
NOTREECHECKS=true
NOTRY=true
BUG=None
Review URL: https://codereview.chromium.org/179813009
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@254743 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base/time')
-rw-r--r-- | base/time/time.cc | 41 | ||||
-rw-r--r-- | base/time/time.h | 40 | ||||
-rw-r--r-- | base/time/time_unittest.cc | 40 |
3 files changed, 6 insertions, 115 deletions
diff --git a/base/time/time.cc b/base/time/time.cc index 2c63886..4605d56 100644 --- a/base/time/time.cc +++ b/base/time/time.cc @@ -17,81 +17,40 @@ namespace base { // TimeDelta ------------------------------------------------------------------ -// static -TimeDelta TimeDelta::Max() { - return TimeDelta(std::numeric_limits<int64>::max()); -} - int TimeDelta::InDays() const { - if (is_max()) { - // Preserve max to prevent overflow. - return std::numeric_limits<int>::max(); - } return static_cast<int>(delta_ / Time::kMicrosecondsPerDay); } int TimeDelta::InHours() const { - if (is_max()) { - // Preserve max to prevent overflow. - return std::numeric_limits<int>::max(); - } return static_cast<int>(delta_ / Time::kMicrosecondsPerHour); } int TimeDelta::InMinutes() const { - if (is_max()) { - // Preserve max to prevent overflow. - return std::numeric_limits<int>::max(); - } return static_cast<int>(delta_ / Time::kMicrosecondsPerMinute); } double TimeDelta::InSecondsF() const { - if (is_max()) { - // Preserve max to prevent overflow. - return std::numeric_limits<double>::infinity(); - } return static_cast<double>(delta_) / Time::kMicrosecondsPerSecond; } int64 TimeDelta::InSeconds() const { - if (is_max()) { - // Preserve max to prevent overflow. - return std::numeric_limits<int64>::max(); - } return delta_ / Time::kMicrosecondsPerSecond; } double TimeDelta::InMillisecondsF() const { - if (is_max()) { - // Preserve max to prevent overflow. - return std::numeric_limits<double>::infinity(); - } return static_cast<double>(delta_) / Time::kMicrosecondsPerMillisecond; } int64 TimeDelta::InMilliseconds() const { - if (is_max()) { - // Preserve max to prevent overflow. - return std::numeric_limits<int64>::max(); - } return delta_ / Time::kMicrosecondsPerMillisecond; } int64 TimeDelta::InMillisecondsRoundedUp() const { - if (is_max()) { - // Preserve max to prevent overflow. - return std::numeric_limits<int64>::max(); - } return (delta_ + Time::kMicrosecondsPerMillisecond - 1) / Time::kMicrosecondsPerMillisecond; } int64 TimeDelta::InMicroseconds() const { - if (is_max()) { - // Preserve max to prevent overflow. - return std::numeric_limits<int64>::max(); - } return delta_; } diff --git a/base/time/time.h b/base/time/time.h index 69a1324..40566b9 100644 --- a/base/time/time.h +++ b/base/time/time.h @@ -61,9 +61,9 @@ class BASE_EXPORT TimeDelta { } // Converts units of time to TimeDeltas. - static TimeDelta FromDays(int days); - static TimeDelta FromHours(int hours); - static TimeDelta FromMinutes(int minutes); + static TimeDelta FromDays(int64 days); + static TimeDelta FromHours(int64 hours); + static TimeDelta FromMinutes(int64 minutes); static TimeDelta FromSeconds(int64 secs); static TimeDelta FromMilliseconds(int64 ms); static TimeDelta FromMicroseconds(int64 us); @@ -79,11 +79,6 @@ class BASE_EXPORT TimeDelta { return TimeDelta(delta); } - // Returns the maximum time delta, which should be greater than any reasonable - // time delta we might compare it to. Adding or subtracting the maximum time - // delta to a time or another time delta has an undefined result. - static TimeDelta Max(); - // Returns the internal numeric value of the TimeDelta object. Please don't // use this and do arithmetic on it, as it is more error prone than using the // provided operators. @@ -92,11 +87,6 @@ class BASE_EXPORT TimeDelta { return delta_; } - // Returns true if the time delta is the maximum time delta. - bool is_max() const { - return delta_ == std::numeric_limits<int64>::max(); - } - #if defined(OS_POSIX) struct timespec ToTimeSpec() const; #endif @@ -503,50 +493,32 @@ class BASE_EXPORT Time { // Inline the TimeDelta factory methods, for fast TimeDelta construction. // static -inline TimeDelta TimeDelta::FromDays(int days) { - // Preserve max to prevent overflow. - if (days == std::numeric_limits<int>::max()) - return Max(); +inline TimeDelta TimeDelta::FromDays(int64 days) { return TimeDelta(days * Time::kMicrosecondsPerDay); } // static -inline TimeDelta TimeDelta::FromHours(int hours) { - // Preserve max to prevent overflow. - if (hours == std::numeric_limits<int>::max()) - return Max(); +inline TimeDelta TimeDelta::FromHours(int64 hours) { return TimeDelta(hours * Time::kMicrosecondsPerHour); } // static -inline TimeDelta TimeDelta::FromMinutes(int minutes) { - // Preserve max to prevent overflow. - if (minutes == std::numeric_limits<int>::max()) - return Max(); +inline TimeDelta TimeDelta::FromMinutes(int64 minutes) { return TimeDelta(minutes * Time::kMicrosecondsPerMinute); } // static inline TimeDelta TimeDelta::FromSeconds(int64 secs) { - // Preserve max to prevent overflow. - if (secs == std::numeric_limits<int64>::max()) - return Max(); return TimeDelta(secs * Time::kMicrosecondsPerSecond); } // static inline TimeDelta TimeDelta::FromMilliseconds(int64 ms) { - // Preserve max to prevent overflow. - if (ms == std::numeric_limits<int64>::max()) - return Max(); return TimeDelta(ms * Time::kMicrosecondsPerMillisecond); } // static inline TimeDelta TimeDelta::FromMicroseconds(int64 us) { - // Preserve max to prevent overflow. - if (us == std::numeric_limits<int64>::max()) - return Max(); return TimeDelta(us); } diff --git a/base/time/time_unittest.cc b/base/time/time_unittest.cc index 40d7bd4..b5d2493 100644 --- a/base/time/time_unittest.cc +++ b/base/time/time_unittest.cc @@ -481,46 +481,6 @@ TEST_F(TimeTest, ExplodeBeforeUnixEpoch) { EXPECT_EQ(1, exploded.millisecond); } -TEST_F(TimeTest, TimeDeltaMax) { - TimeDelta max = TimeDelta::Max(); - EXPECT_TRUE(max.is_max()); - EXPECT_EQ(max, TimeDelta::Max()); - EXPECT_GT(max, TimeDelta::FromDays(100 * 365)); - EXPECT_GT(max, TimeDelta()); -} - -TEST_F(TimeTest, TimeDeltaMaxConversions) { - TimeDelta t = TimeDelta::Max(); - EXPECT_EQ(std::numeric_limits<int64>::max(), t.ToInternalValue()); - - EXPECT_EQ(std::numeric_limits<int>::max(), t.InDays()); - EXPECT_EQ(std::numeric_limits<int>::max(), t.InHours()); - EXPECT_EQ(std::numeric_limits<int>::max(), t.InMinutes()); - EXPECT_EQ(std::numeric_limits<double>::infinity(), t.InSecondsF()); - EXPECT_EQ(std::numeric_limits<int64>::max(), t.InSeconds()); - EXPECT_EQ(std::numeric_limits<double>::infinity(), t.InMillisecondsF()); - EXPECT_EQ(std::numeric_limits<int64>::max(), t.InMilliseconds()); - EXPECT_EQ(std::numeric_limits<int64>::max(), t.InMillisecondsRoundedUp()); - - t = TimeDelta::FromDays(std::numeric_limits<int>::max()); - EXPECT_TRUE(t.is_max()); - - t = TimeDelta::FromHours(std::numeric_limits<int>::max()); - EXPECT_TRUE(t.is_max()); - - t = TimeDelta::FromMinutes(std::numeric_limits<int>::max()); - EXPECT_TRUE(t.is_max()); - - t = TimeDelta::FromSeconds(std::numeric_limits<int64>::max()); - EXPECT_TRUE(t.is_max()); - - t = TimeDelta::FromMilliseconds(std::numeric_limits<int64>::max()); - EXPECT_TRUE(t.is_max()); - - t = TimeDelta::FromMicroseconds(std::numeric_limits<int64>::max()); - EXPECT_TRUE(t.is_max()); -} - TEST_F(TimeTest, Max) { Time max = Time::Max(); EXPECT_TRUE(max.is_max()); |