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 293 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
304 // Warning: Be careful when writing code that performs math on time values, | 304 // Warning: Be careful when writing code that performs math on time values, |
305 // since it's possible to produce a valid "zero" result that should not be | 305 // since it's possible to produce a valid "zero" result that should not be |
306 // interpreted as a "null" value. | 306 // interpreted as a "null" value. |
307 bool is_null() const { | 307 bool is_null() const { |
308 return us_ == 0; | 308 return us_ == 0; |
309 } | 309 } |
310 | 310 |
311 // Returns true if this object represents the maximum time. | 311 // Returns true if this object represents the maximum time. |
312 bool is_max() const { return us_ == std::numeric_limits<int64_t>::max(); } | 312 bool is_max() const { return us_ == std::numeric_limits<int64_t>::max(); } |
313 | 313 |
| 314 // Returns the maximum time, which should be greater than any reasonable time |
| 315 // with which we might compare it. |
| 316 static TimeClass Max() { |
| 317 return TimeClass(std::numeric_limits<int64_t>::max()); |
| 318 } |
| 319 |
314 // For serializing only. Use FromInternalValue() to reconstitute. Please don't | 320 // For serializing only. Use FromInternalValue() to reconstitute. Please don't |
315 // use this and do arithmetic on it, as it is more error prone than using the | 321 // use this and do arithmetic on it, as it is more error prone than using the |
316 // provided operators. | 322 // provided operators. |
317 int64_t ToInternalValue() const { return us_; } | 323 int64_t ToInternalValue() const { return us_; } |
318 | 324 |
319 TimeClass& operator=(TimeClass other) { | 325 TimeClass& operator=(TimeClass other) { |
320 us_ = other.us_; | 326 us_ = other.us_; |
321 return *(static_cast<TimeClass*>(this)); | 327 return *(static_cast<TimeClass*>(this)); |
322 } | 328 } |
323 | 329 |
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
431 } | 437 } |
432 | 438 |
433 // Returns the time for epoch in Unix-like system (Jan 1, 1970). | 439 // Returns the time for epoch in Unix-like system (Jan 1, 1970). |
434 static Time UnixEpoch(); | 440 static Time UnixEpoch(); |
435 | 441 |
436 // Returns the current time. Watch out, the system might adjust its clock | 442 // Returns the current time. Watch out, the system might adjust its clock |
437 // in which case time will actually go backwards. We don't guarantee that | 443 // in which case time will actually go backwards. We don't guarantee that |
438 // times are increasing, or that two calls to Now() won't be the same. | 444 // times are increasing, or that two calls to Now() won't be the same. |
439 static Time Now(); | 445 static Time Now(); |
440 | 446 |
441 // Returns the maximum time, which should be greater than any reasonable time | |
442 // with which we might compare it. | |
443 static Time Max(); | |
444 | |
445 // Returns the current time. Same as Now() except that this function always | 447 // Returns the current time. Same as Now() except that this function always |
446 // uses system time so that there are no discrepancies between the returned | 448 // uses system time so that there are no discrepancies between the returned |
447 // time and system time even on virtual environments including our test bot. | 449 // time and system time even on virtual environments including our test bot. |
448 // For timing sensitive unittests, this function should be used. | 450 // For timing sensitive unittests, this function should be used. |
449 static Time NowFromSystemTime(); | 451 static Time NowFromSystemTime(); |
450 | 452 |
451 // Converts to/from time_t in UTC and a Time class. | 453 // Converts to/from time_t in UTC and a Time class. |
452 // TODO(brettw) this should be removed once everybody starts using the |Time| | 454 // TODO(brettw) this should be removed once everybody starts using the |Time| |
453 // class. | 455 // class. |
454 static Time FromTimeT(time_t tt); | 456 static Time FromTimeT(time_t tt); |
(...skipping 334 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
789 static void WaitUntilInitializedWin(); | 791 static void WaitUntilInitializedWin(); |
790 #endif | 792 #endif |
791 }; | 793 }; |
792 | 794 |
793 // For logging use only. | 795 // For logging use only. |
794 BASE_EXPORT std::ostream& operator<<(std::ostream& os, ThreadTicks time_ticks); | 796 BASE_EXPORT std::ostream& operator<<(std::ostream& os, ThreadTicks time_ticks); |
795 | 797 |
796 } // namespace base | 798 } // namespace base |
797 | 799 |
798 #endif // BASE_TIME_TIME_H_ | 800 #endif // BASE_TIME_TIME_H_ |
OLD | NEW |