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) (See http://crbug.com/14734). System-dependent | 7 // (1601-01-01 00:00:00 UTC) (See http://crbug.com/14734). System-dependent |
8 // clock interface routines are defined in time_PLATFORM.cc. | 8 // clock interface routines are defined in time_PLATFORM.cc. |
9 // | 9 // |
10 // TimeDelta represents a duration of time, internally represented in | 10 // TimeDelta represents a duration of time, internally represented in |
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
151 return *this; | 151 return *this; |
152 } | 152 } |
153 TimeDelta& operator-=(TimeDelta other) { | 153 TimeDelta& operator-=(TimeDelta other) { |
154 delta_ -= other.delta_; | 154 delta_ -= other.delta_; |
155 return *this; | 155 return *this; |
156 } | 156 } |
157 TimeDelta operator-() const { | 157 TimeDelta operator-() const { |
158 return TimeDelta(-delta_); | 158 return TimeDelta(-delta_); |
159 } | 159 } |
160 | 160 |
161 // Computations with ints, note that we only allow multiplicative operations | 161 // Computations with ints, note that we only allow multiplicative operations |
rvargas (doing something else)
2015/02/20 21:49:42
This comment looks stale now.
michaeln
2015/02/20 22:18:04
It's still valid, there is no operator+=(int).
rvargas (doing something else)
2015/02/20 22:44:56
"we only allow multiplicative operations with ints
| |
162 // with ints, and additive operations with other deltas. | 162 // with ints, and additive operations with other deltas. |
163 TimeDelta operator*(int64 a) const { | 163 TimeDelta operator*(int64 a) const { |
164 return TimeDelta(delta_ * a); | 164 return TimeDelta(delta_ * a); |
165 } | 165 } |
166 TimeDelta operator/(int64 a) const { | 166 TimeDelta operator/(int64 a) const { |
167 return TimeDelta(delta_ / a); | 167 return TimeDelta(delta_ / a); |
168 } | 168 } |
169 TimeDelta& operator*=(int64 a) { | 169 TimeDelta& operator*=(int64 a) { |
170 delta_ *= a; | 170 delta_ *= a; |
171 return *this; | 171 return *this; |
172 } | 172 } |
173 TimeDelta& operator/=(int64 a) { | 173 TimeDelta& operator/=(int64 a) { |
174 delta_ /= a; | 174 delta_ /= a; |
175 return *this; | 175 return *this; |
176 } | 176 } |
177 int64 operator/(TimeDelta a) const { | 177 int64 operator/(TimeDelta a) const { |
178 return delta_ / a.delta_; | 178 return delta_ / a.delta_; |
179 } | 179 } |
180 | 180 |
181 // Multiplicative computations with floats. | |
182 TimeDelta multiply_by(double a) const { | |
rvargas (doing something else)
2015/02/20 21:49:42
I know that in general we prefer named methods ove
michaeln
2015/02/20 22:18:04
i initially tried it with operators but adding an
rvargas (doing something else)
2015/02/20 22:44:56
hmmm, how about
template<typename T>
TimeDelt
| |
183 return TimeDelta(delta_ * a); | |
184 } | |
185 TimeDelta divide_by(double a) const { | |
186 return TimeDelta(delta_ / a); | |
187 } | |
188 | |
181 // Defined below because it depends on the definition of the other classes. | 189 // Defined below because it depends on the definition of the other classes. |
182 Time operator+(Time t) const; | 190 Time operator+(Time t) const; |
183 TimeTicks operator+(TimeTicks t) const; | 191 TimeTicks operator+(TimeTicks t) const; |
184 | 192 |
185 // Comparison operators. | 193 // Comparison operators. |
186 bool operator==(TimeDelta other) const { | 194 bool operator==(TimeDelta other) const { |
187 return delta_ == other.delta_; | 195 return delta_ == other.delta_; |
188 } | 196 } |
189 bool operator!=(TimeDelta other) const { | 197 bool operator!=(TimeDelta other) const { |
190 return delta_ != other.delta_; | 198 return delta_ != other.delta_; |
(...skipping 563 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
754 inline TimeTicks TimeDelta::operator+(TimeTicks t) const { | 762 inline TimeTicks TimeDelta::operator+(TimeTicks t) const { |
755 return TimeTicks(t.ticks_ + delta_); | 763 return TimeTicks(t.ticks_ + delta_); |
756 } | 764 } |
757 | 765 |
758 // For logging use only. | 766 // For logging use only. |
759 BASE_EXPORT std::ostream& operator<<(std::ostream& os, TimeTicks time_ticks); | 767 BASE_EXPORT std::ostream& operator<<(std::ostream& os, TimeTicks time_ticks); |
760 | 768 |
761 } // namespace base | 769 } // namespace base |
762 | 770 |
763 #endif // BASE_TIME_TIME_H_ | 771 #endif // BASE_TIME_TIME_H_ |
OLD | NEW |