OLD | NEW |
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.h" | 5 #include "base/time.h" |
6 | 6 |
7 #include <math.h> | 7 #include <math.h> |
8 #if defined(OS_WIN) | |
9 #include <float.h> | |
10 #endif | |
11 | |
12 #include <limits> | 8 #include <limits> |
13 | 9 |
| 10 #include "base/float_util.h" |
14 #include "base/strings/sys_string_conversions.h" | 11 #include "base/strings/sys_string_conversions.h" |
15 #include "base/third_party/nspr/prtime.h" | 12 #include "base/third_party/nspr/prtime.h" |
16 | 13 |
17 #include "base/logging.h" | 14 #include "base/logging.h" |
18 | 15 |
19 namespace base { | 16 namespace base { |
20 | 17 |
21 namespace { | |
22 #if defined(OS_WIN) | |
23 inline bool isnan(double num) { return !!_isnan(num); } | |
24 #endif | |
25 } | |
26 | |
27 // TimeDelta ------------------------------------------------------------------ | 18 // TimeDelta ------------------------------------------------------------------ |
28 | 19 |
29 int TimeDelta::InDays() const { | 20 int TimeDelta::InDays() const { |
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 return static_cast<int>(delta_ / Time::kMicrosecondsPerHour); | 25 return static_cast<int>(delta_ / Time::kMicrosecondsPerHour); |
35 } | 26 } |
36 | 27 |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
89 if (std::numeric_limits<int64>::max() - kTimeTToMicrosecondsOffset <= us_) { | 80 if (std::numeric_limits<int64>::max() - kTimeTToMicrosecondsOffset <= us_) { |
90 DLOG(WARNING) << "Overflow when converting base::Time with internal " << | 81 DLOG(WARNING) << "Overflow when converting base::Time with internal " << |
91 "value " << us_ << " to time_t."; | 82 "value " << us_ << " to time_t."; |
92 return std::numeric_limits<time_t>::max(); | 83 return std::numeric_limits<time_t>::max(); |
93 } | 84 } |
94 return (us_ - kTimeTToMicrosecondsOffset) / kMicrosecondsPerSecond; | 85 return (us_ - kTimeTToMicrosecondsOffset) / kMicrosecondsPerSecond; |
95 } | 86 } |
96 | 87 |
97 // static | 88 // static |
98 Time Time::FromDoubleT(double dt) { | 89 Time Time::FromDoubleT(double dt) { |
99 if (dt == 0 || isnan(dt)) | 90 if (dt == 0 || IsNaN(dt)) |
100 return Time(); // Preserve 0 so we can tell it doesn't exist. | 91 return Time(); // Preserve 0 so we can tell it doesn't exist. |
101 if (dt == std::numeric_limits<double>::max()) | 92 if (dt == std::numeric_limits<double>::max()) |
102 return Max(); | 93 return Max(); |
103 return Time(static_cast<int64>((dt * | 94 return Time(static_cast<int64>((dt * |
104 static_cast<double>(kMicrosecondsPerSecond)) + | 95 static_cast<double>(kMicrosecondsPerSecond)) + |
105 kTimeTToMicrosecondsOffset)); | 96 kTimeTToMicrosecondsOffset)); |
106 } | 97 } |
107 | 98 |
108 double Time::ToDoubleT() const { | 99 double Time::ToDoubleT() const { |
109 if (is_null()) | 100 if (is_null()) |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
187 return is_in_range(month, 1, 12) && | 178 return is_in_range(month, 1, 12) && |
188 is_in_range(day_of_week, 0, 6) && | 179 is_in_range(day_of_week, 0, 6) && |
189 is_in_range(day_of_month, 1, 31) && | 180 is_in_range(day_of_month, 1, 31) && |
190 is_in_range(hour, 0, 23) && | 181 is_in_range(hour, 0, 23) && |
191 is_in_range(minute, 0, 59) && | 182 is_in_range(minute, 0, 59) && |
192 is_in_range(second, 0, 60) && | 183 is_in_range(second, 0, 60) && |
193 is_in_range(millisecond, 0, 999); | 184 is_in_range(millisecond, 0, 999); |
194 } | 185 } |
195 | 186 |
196 } // namespace base | 187 } // namespace base |
OLD | NEW |