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

Side by Side Diff: base/time/time.cc

Issue 179813009: Revert of Reland "Add base::TimeDelta::Max()" (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 9 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « base/time/time.h ('k') | base/time/time_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "base/time/time.h" 5 #include "base/time/time.h"
6 6
7 #include <limits> 7 #include <limits>
8 #include <ostream> 8 #include <ostream>
9 9
10 #include "base/float_util.h" 10 #include "base/float_util.h"
11 #include "base/lazy_instance.h" 11 #include "base/lazy_instance.h"
12 #include "base/logging.h" 12 #include "base/logging.h"
13 #include "base/third_party/nspr/prtime.h" 13 #include "base/third_party/nspr/prtime.h"
14 #include "base/third_party/nspr/prtypes.h" 14 #include "base/third_party/nspr/prtypes.h"
15 15
16 namespace base { 16 namespace base {
17 17
18 // TimeDelta ------------------------------------------------------------------ 18 // TimeDelta ------------------------------------------------------------------
19 19
20 // static
21 TimeDelta TimeDelta::Max() {
22 return TimeDelta(std::numeric_limits<int64>::max());
23 }
24
25 int TimeDelta::InDays() const { 20 int TimeDelta::InDays() const {
26 if (is_max()) {
27 // Preserve max to prevent overflow.
28 return std::numeric_limits<int>::max();
29 }
30 return static_cast<int>(delta_ / Time::kMicrosecondsPerDay); 21 return static_cast<int>(delta_ / Time::kMicrosecondsPerDay);
31 } 22 }
32 23
33 int TimeDelta::InHours() const { 24 int TimeDelta::InHours() const {
34 if (is_max()) {
35 // Preserve max to prevent overflow.
36 return std::numeric_limits<int>::max();
37 }
38 return static_cast<int>(delta_ / Time::kMicrosecondsPerHour); 25 return static_cast<int>(delta_ / Time::kMicrosecondsPerHour);
39 } 26 }
40 27
41 int TimeDelta::InMinutes() const { 28 int TimeDelta::InMinutes() const {
42 if (is_max()) {
43 // Preserve max to prevent overflow.
44 return std::numeric_limits<int>::max();
45 }
46 return static_cast<int>(delta_ / Time::kMicrosecondsPerMinute); 29 return static_cast<int>(delta_ / Time::kMicrosecondsPerMinute);
47 } 30 }
48 31
49 double TimeDelta::InSecondsF() const { 32 double TimeDelta::InSecondsF() const {
50 if (is_max()) {
51 // Preserve max to prevent overflow.
52 return std::numeric_limits<double>::infinity();
53 }
54 return static_cast<double>(delta_) / Time::kMicrosecondsPerSecond; 33 return static_cast<double>(delta_) / Time::kMicrosecondsPerSecond;
55 } 34 }
56 35
57 int64 TimeDelta::InSeconds() const { 36 int64 TimeDelta::InSeconds() const {
58 if (is_max()) {
59 // Preserve max to prevent overflow.
60 return std::numeric_limits<int64>::max();
61 }
62 return delta_ / Time::kMicrosecondsPerSecond; 37 return delta_ / Time::kMicrosecondsPerSecond;
63 } 38 }
64 39
65 double TimeDelta::InMillisecondsF() const { 40 double TimeDelta::InMillisecondsF() const {
66 if (is_max()) {
67 // Preserve max to prevent overflow.
68 return std::numeric_limits<double>::infinity();
69 }
70 return static_cast<double>(delta_) / Time::kMicrosecondsPerMillisecond; 41 return static_cast<double>(delta_) / Time::kMicrosecondsPerMillisecond;
71 } 42 }
72 43
73 int64 TimeDelta::InMilliseconds() const { 44 int64 TimeDelta::InMilliseconds() const {
74 if (is_max()) {
75 // Preserve max to prevent overflow.
76 return std::numeric_limits<int64>::max();
77 }
78 return delta_ / Time::kMicrosecondsPerMillisecond; 45 return delta_ / Time::kMicrosecondsPerMillisecond;
79 } 46 }
80 47
81 int64 TimeDelta::InMillisecondsRoundedUp() const { 48 int64 TimeDelta::InMillisecondsRoundedUp() const {
82 if (is_max()) {
83 // Preserve max to prevent overflow.
84 return std::numeric_limits<int64>::max();
85 }
86 return (delta_ + Time::kMicrosecondsPerMillisecond - 1) / 49 return (delta_ + Time::kMicrosecondsPerMillisecond - 1) /
87 Time::kMicrosecondsPerMillisecond; 50 Time::kMicrosecondsPerMillisecond;
88 } 51 }
89 52
90 int64 TimeDelta::InMicroseconds() const { 53 int64 TimeDelta::InMicroseconds() const {
91 if (is_max()) {
92 // Preserve max to prevent overflow.
93 return std::numeric_limits<int64>::max();
94 }
95 return delta_; 54 return delta_;
96 } 55 }
97 56
98 // Time ----------------------------------------------------------------------- 57 // Time -----------------------------------------------------------------------
99 58
100 // static 59 // static
101 Time Time::Max() { 60 Time Time::Max() {
102 return Time(std::numeric_limits<int64>::max()); 61 return Time(std::numeric_limits<int64>::max());
103 } 62 }
104 63
(...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after
264 return is_in_range(month, 1, 12) && 223 return is_in_range(month, 1, 12) &&
265 is_in_range(day_of_week, 0, 6) && 224 is_in_range(day_of_week, 0, 6) &&
266 is_in_range(day_of_month, 1, 31) && 225 is_in_range(day_of_month, 1, 31) &&
267 is_in_range(hour, 0, 23) && 226 is_in_range(hour, 0, 23) &&
268 is_in_range(minute, 0, 59) && 227 is_in_range(minute, 0, 59) &&
269 is_in_range(second, 0, 60) && 228 is_in_range(second, 0, 60) &&
270 is_in_range(millisecond, 0, 999); 229 is_in_range(millisecond, 0, 999);
271 } 230 }
272 231
273 } // namespace base 232 } // namespace base
OLDNEW
« no previous file with comments | « base/time/time.h ('k') | base/time/time_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698