| 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 // Time represents an absolute point in coordinated universal time (UTC), | 5 // Time represents an absolute point in coordinated universal time (UTC), |
| 6 // internally represented as microseconds (s/1,000,000) since the Windows epoch | 6 // internally represented as microseconds (s/1,000,000) since the Windows epoch |
| 7 // (1601-01-01 00:00:00 UTC). System-dependent clock interface routines are | 7 // (1601-01-01 00:00:00 UTC). System-dependent clock interface routines are |
| 8 // defined in time_PLATFORM.cc. Note that values for Time may skew and jump | 8 // defined in time_PLATFORM.cc. Note that values for Time may skew and jump |
| 9 // around as the operating system makes adjustments to synchronize (e.g., with | 9 // around as the operating system makes adjustments to synchronize (e.g., with |
| 10 // NTP servers). Thus, client code that uses the Time class must account for | 10 // NTP servers). Thus, client code that uses the Time class must account for |
| (...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 123 | 123 |
| 124 // Converts an integer value representing TimeDelta to a class. This is used | 124 // Converts an integer value representing TimeDelta to a class. This is used |
| 125 // when deserializing a |TimeDelta| structure, using a value known to be | 125 // when deserializing a |TimeDelta| structure, using a value known to be |
| 126 // compatible. It is not provided as a constructor because the integer type | 126 // compatible. It is not provided as a constructor because the integer type |
| 127 // may be unclear from the perspective of a caller. | 127 // may be unclear from the perspective of a caller. |
| 128 static TimeDelta FromInternalValue(int64_t delta) { return TimeDelta(delta); } | 128 static TimeDelta FromInternalValue(int64_t delta) { return TimeDelta(delta); } |
| 129 | 129 |
| 130 // Returns the maximum time delta, which should be greater than any reasonable | 130 // Returns the maximum time delta, which should be greater than any reasonable |
| 131 // time delta we might compare it to. Adding or subtracting the maximum time | 131 // time delta we might compare it to. Adding or subtracting the maximum time |
| 132 // delta to a time or another time delta has an undefined result. | 132 // delta to a time or another time delta has an undefined result. |
| 133 static TimeDelta Max(); | 133 static constexpr TimeDelta Max(); |
| 134 | 134 |
| 135 // Returns the internal numeric value of the TimeDelta object. Please don't | 135 // Returns the internal numeric value of the TimeDelta object. Please don't |
| 136 // use this and do arithmetic on it, as it is more error prone than using the | 136 // use this and do arithmetic on it, as it is more error prone than using the |
| 137 // provided operators. | 137 // provided operators. |
| 138 // For serializing, use FromInternalValue to reconstitute. | 138 // For serializing, use FromInternalValue to reconstitute. |
| 139 int64_t ToInternalValue() const { return delta_; } | 139 int64_t ToInternalValue() const { return delta_; } |
| 140 | 140 |
| 141 // Returns the magnitude (absolute value) of this TimeDelta. | 141 // Returns the magnitude (absolute value) of this TimeDelta. |
| 142 TimeDelta magnitude() const { | 142 TimeDelta magnitude() const { |
| 143 // Some toolchains provide an incomplete C++11 implementation and lack an | 143 // Some toolchains provide an incomplete C++11 implementation and lack an |
| (...skipping 520 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 664 constexpr TimeDelta TimeDelta::FromMillisecondsD(double ms) { | 664 constexpr TimeDelta TimeDelta::FromMillisecondsD(double ms) { |
| 665 return FromDouble(ms * Time::kMicrosecondsPerMillisecond); | 665 return FromDouble(ms * Time::kMicrosecondsPerMillisecond); |
| 666 } | 666 } |
| 667 | 667 |
| 668 // static | 668 // static |
| 669 constexpr TimeDelta TimeDelta::FromMicroseconds(int64_t us) { | 669 constexpr TimeDelta TimeDelta::FromMicroseconds(int64_t us) { |
| 670 return TimeDelta(us); | 670 return TimeDelta(us); |
| 671 } | 671 } |
| 672 | 672 |
| 673 // static | 673 // static |
| 674 constexpr TimeDelta TimeDelta::Max() { |
| 675 return TimeDelta(std::numeric_limits<int64_t>::max()); |
| 676 } |
| 677 |
| 678 // static |
| 674 constexpr TimeDelta TimeDelta::FromDouble(double value) { | 679 constexpr TimeDelta TimeDelta::FromDouble(double value) { |
| 675 // TODO(crbug.com/612601): Use saturated_cast<int64_t>(value) once we sort out | 680 // TODO(crbug.com/612601): Use saturated_cast<int64_t>(value) once we sort out |
| 676 // the Min() behavior. | 681 // the Min() behavior. |
| 677 return value > std::numeric_limits<int64_t>::max() | 682 return value > std::numeric_limits<int64_t>::max() |
| 678 ? Max() | 683 ? Max() |
| 679 : value < -std::numeric_limits<int64_t>::max() | 684 : value < -std::numeric_limits<int64_t>::max() |
| 680 ? -Max() | 685 ? -Max() |
| 681 : TimeDelta(static_cast<int64_t>(value)); | 686 : TimeDelta(static_cast<int64_t>(value)); |
| 682 } | 687 } |
| 683 | 688 |
| (...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 851 static void WaitUntilInitializedWin(); | 856 static void WaitUntilInitializedWin(); |
| 852 #endif | 857 #endif |
| 853 }; | 858 }; |
| 854 | 859 |
| 855 // For logging use only. | 860 // For logging use only. |
| 856 BASE_EXPORT std::ostream& operator<<(std::ostream& os, ThreadTicks time_ticks); | 861 BASE_EXPORT std::ostream& operator<<(std::ostream& os, ThreadTicks time_ticks); |
| 857 | 862 |
| 858 } // namespace base | 863 } // namespace base |
| 859 | 864 |
| 860 #endif // BASE_TIME_TIME_H_ | 865 #endif // BASE_TIME_TIME_H_ |
| OLD | NEW |