| 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) | 8 #if defined(OS_WIN) |
| 9 #include <float.h> | 9 #include <float.h> |
| 10 #endif | 10 #endif |
| (...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 109 if (is_null()) | 109 if (is_null()) |
| 110 return 0; // Preserve 0 so we can tell it doesn't exist. | 110 return 0; // Preserve 0 so we can tell it doesn't exist. |
| 111 if (is_max()) { | 111 if (is_max()) { |
| 112 // Preserve max without offset to prevent overflow. | 112 // Preserve max without offset to prevent overflow. |
| 113 return std::numeric_limits<double>::max(); | 113 return std::numeric_limits<double>::max(); |
| 114 } | 114 } |
| 115 return (static_cast<double>(us_ - kTimeTToMicrosecondsOffset) / | 115 return (static_cast<double>(us_ - kTimeTToMicrosecondsOffset) / |
| 116 static_cast<double>(kMicrosecondsPerSecond)); | 116 static_cast<double>(kMicrosecondsPerSecond)); |
| 117 } | 117 } |
| 118 | 118 |
| 119 #if defined(OS_POSIX) |
| 120 // static |
| 121 Time Time::FromTimeSpec(const timespec& ts) { |
| 122 return FromDoubleT(ts.tv_sec + |
| 123 static_cast<double>(ts.tv_nsec) / |
| 124 base::Time::kNanosecondsPerSecond); |
| 125 } |
| 126 #endif |
| 127 |
| 119 // static | 128 // static |
| 120 Time Time::FromJsTime(double ms_since_epoch) { | 129 Time Time::FromJsTime(double ms_since_epoch) { |
| 121 // The epoch is a valid time, so this constructor doesn't interpret | 130 // The epoch is a valid time, so this constructor doesn't interpret |
| 122 // 0 as the null time. | 131 // 0 as the null time. |
| 123 if (ms_since_epoch == std::numeric_limits<double>::max()) | 132 if (ms_since_epoch == std::numeric_limits<double>::max()) |
| 124 return Max(); | 133 return Max(); |
| 125 return Time(static_cast<int64>(ms_since_epoch * kMicrosecondsPerMillisecond) + | 134 return Time(static_cast<int64>(ms_since_epoch * kMicrosecondsPerMillisecond) + |
| 126 kTimeTToMicrosecondsOffset); | 135 kTimeTToMicrosecondsOffset); |
| 127 } | 136 } |
| 128 | 137 |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 187 return is_in_range(month, 1, 12) && | 196 return is_in_range(month, 1, 12) && |
| 188 is_in_range(day_of_week, 0, 6) && | 197 is_in_range(day_of_week, 0, 6) && |
| 189 is_in_range(day_of_month, 1, 31) && | 198 is_in_range(day_of_month, 1, 31) && |
| 190 is_in_range(hour, 0, 23) && | 199 is_in_range(hour, 0, 23) && |
| 191 is_in_range(minute, 0, 59) && | 200 is_in_range(minute, 0, 59) && |
| 192 is_in_range(second, 0, 60) && | 201 is_in_range(second, 0, 60) && |
| 193 is_in_range(millisecond, 0, 999); | 202 is_in_range(millisecond, 0, 999); |
| 194 } | 203 } |
| 195 | 204 |
| 196 } // namespace base | 205 } // namespace base |
| OLD | NEW |