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/time.h" | 5 #include "base/time/time.h" |
6 | 6 |
| 7 #include <cmath> |
7 #include <ios> | 8 #include <ios> |
8 #include <limits> | 9 #include <limits> |
9 #include <ostream> | 10 #include <ostream> |
10 #include <sstream> | 11 #include <sstream> |
11 | 12 |
12 #include "base/float_util.h" | |
13 #include "base/lazy_instance.h" | 13 #include "base/lazy_instance.h" |
14 #include "base/logging.h" | 14 #include "base/logging.h" |
15 #include "base/strings/stringprintf.h" | 15 #include "base/strings/stringprintf.h" |
16 #include "base/third_party/nspr/prtime.h" | 16 #include "base/third_party/nspr/prtime.h" |
17 | 17 |
18 namespace base { | 18 namespace base { |
19 | 19 |
20 // TimeDelta ------------------------------------------------------------------ | 20 // TimeDelta ------------------------------------------------------------------ |
21 | 21 |
22 // static | 22 // static |
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
154 if (std::numeric_limits<int64>::max() - kTimeTToMicrosecondsOffset <= us_) { | 154 if (std::numeric_limits<int64>::max() - kTimeTToMicrosecondsOffset <= us_) { |
155 DLOG(WARNING) << "Overflow when converting base::Time with internal " << | 155 DLOG(WARNING) << "Overflow when converting base::Time with internal " << |
156 "value " << us_ << " to time_t."; | 156 "value " << us_ << " to time_t."; |
157 return std::numeric_limits<time_t>::max(); | 157 return std::numeric_limits<time_t>::max(); |
158 } | 158 } |
159 return (us_ - kTimeTToMicrosecondsOffset) / kMicrosecondsPerSecond; | 159 return (us_ - kTimeTToMicrosecondsOffset) / kMicrosecondsPerSecond; |
160 } | 160 } |
161 | 161 |
162 // static | 162 // static |
163 Time Time::FromDoubleT(double dt) { | 163 Time Time::FromDoubleT(double dt) { |
164 if (dt == 0 || IsNaN(dt)) | 164 if (dt == 0 || std::isnan(dt)) |
165 return Time(); // Preserve 0 so we can tell it doesn't exist. | 165 return Time(); // Preserve 0 so we can tell it doesn't exist. |
166 if (dt == std::numeric_limits<double>::infinity()) | 166 if (dt == std::numeric_limits<double>::infinity()) |
167 return Max(); | 167 return Max(); |
168 return Time(static_cast<int64>((dt * | 168 return Time(static_cast<int64>((dt * |
169 static_cast<double>(kMicrosecondsPerSecond)) + | 169 static_cast<double>(kMicrosecondsPerSecond)) + |
170 kTimeTToMicrosecondsOffset)); | 170 kTimeTToMicrosecondsOffset)); |
171 } | 171 } |
172 | 172 |
173 double Time::ToDoubleT() const { | 173 double Time::ToDoubleT() const { |
174 if (is_null()) | 174 if (is_null()) |
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
337 return is_in_range(month, 1, 12) && | 337 return is_in_range(month, 1, 12) && |
338 is_in_range(day_of_week, 0, 6) && | 338 is_in_range(day_of_week, 0, 6) && |
339 is_in_range(day_of_month, 1, 31) && | 339 is_in_range(day_of_month, 1, 31) && |
340 is_in_range(hour, 0, 23) && | 340 is_in_range(hour, 0, 23) && |
341 is_in_range(minute, 0, 59) && | 341 is_in_range(minute, 0, 59) && |
342 is_in_range(second, 0, 60) && | 342 is_in_range(second, 0, 60) && |
343 is_in_range(millisecond, 0, 999); | 343 is_in_range(millisecond, 0, 999); |
344 } | 344 } |
345 | 345 |
346 } // namespace base | 346 } // namespace base |
OLD | NEW |