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