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 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
49 #ifndef BASE_TIME_TIME_H_ | 49 #ifndef BASE_TIME_TIME_H_ |
50 #define BASE_TIME_TIME_H_ | 50 #define BASE_TIME_TIME_H_ |
51 | 51 |
52 #include <stdint.h> | 52 #include <stdint.h> |
53 #include <time.h> | 53 #include <time.h> |
54 | 54 |
55 #include <iosfwd> | 55 #include <iosfwd> |
56 #include <limits> | 56 #include <limits> |
57 | 57 |
58 #include "base/base_export.h" | 58 #include "base/base_export.h" |
59 #include "base/compiler_specific.h" | |
59 #include "base/numerics/safe_math.h" | 60 #include "base/numerics/safe_math.h" |
60 #include "build/build_config.h" | 61 #include "build/build_config.h" |
61 | 62 |
62 #if defined(OS_MACOSX) | 63 #if defined(OS_MACOSX) |
63 #include <CoreFoundation/CoreFoundation.h> | 64 #include <CoreFoundation/CoreFoundation.h> |
64 // Avoid Mac system header macro leak. | 65 // Avoid Mac system header macro leak. |
65 #undef TYPE_BOOL | 66 #undef TYPE_BOOL |
66 #endif | 67 #endif |
67 | 68 |
68 #if defined(OS_POSIX) | 69 #if defined(OS_POSIX) |
(...skipping 348 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
417 int hour; // Hour within the current day (0-23) | 418 int hour; // Hour within the current day (0-23) |
418 int minute; // Minute within the current hour (0-59) | 419 int minute; // Minute within the current hour (0-59) |
419 int second; // Second within the current minute (0-59 plus leap | 420 int second; // Second within the current minute (0-59 plus leap |
420 // seconds which may take it up to 60). | 421 // seconds which may take it up to 60). |
421 int millisecond; // Milliseconds within the current second (0-999) | 422 int millisecond; // Milliseconds within the current second (0-999) |
422 | 423 |
423 // A cursory test for whether the data members are within their | 424 // A cursory test for whether the data members are within their |
424 // respective ranges. A 'true' return value does not guarantee the | 425 // respective ranges. A 'true' return value does not guarantee the |
425 // Exploded value can be successfully converted to a Time value. | 426 // Exploded value can be successfully converted to a Time value. |
426 bool HasValidValues() const; | 427 bool HasValidValues() const; |
428 bool operator!=(const Exploded& rhs); | |
Mark Mentovai
2016/05/24 18:27:27
Put a blank line before this, because it’s not rel
mmenke
2016/05/24 18:31:18
I'm not sure we can check day of week...So as I be
Mark Mentovai
2016/05/24 18:34:13
mmenke wrote:
maksims (do not use this acc)
2016/05/26 04:38:18
Done.
| |
427 }; | 429 }; |
428 | 430 |
429 // Contains the NULL time. Use Time::Now() to get the current time. | 431 // Contains the NULL time. Use Time::Now() to get the current time. |
430 Time() : TimeBase(0) { | 432 Time() : TimeBase(0) { |
431 } | 433 } |
432 | 434 |
433 // Returns the time for epoch in Unix-like system (Jan 1, 1970). | 435 // Returns the time for epoch in Unix-like system (Jan 1, 1970). |
434 static Time UnixEpoch(); | 436 static Time UnixEpoch(); |
435 | 437 |
436 // Returns the current time. Watch out, the system might adjust its clock | 438 // Returns the current time. Watch out, the system might adjust its clock |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
511 // this function to deactivate the high resolution timer. | 513 // this function to deactivate the high resolution timer. |
512 static bool ActivateHighResolutionTimer(bool activate); | 514 static bool ActivateHighResolutionTimer(bool activate); |
513 | 515 |
514 // Returns true if the high resolution timer is both enabled and activated. | 516 // Returns true if the high resolution timer is both enabled and activated. |
515 // This is provided for testing only, and is not tracked in a thread-safe | 517 // This is provided for testing only, and is not tracked in a thread-safe |
516 // way. | 518 // way. |
517 static bool IsHighResolutionTimerInUse(); | 519 static bool IsHighResolutionTimerInUse(); |
518 #endif | 520 #endif |
519 | 521 |
520 // Converts an exploded structure representing either the local time or UTC | 522 // Converts an exploded structure representing either the local time or UTC |
521 // into a Time class. | 523 // into a Time class. |
mmenke
2016/05/24 16:08:33
Should add a TODO here:
TODO(maksims): Get rid o
maksims (do not use this acc)
2016/05/26 04:38:18
Done.
| |
522 static Time FromUTCExploded(const Exploded& exploded) { | 524 static Time FromUTCExploded(const Exploded& exploded) { |
523 return FromExploded(false, exploded); | 525 base::Time time; |
526 ignore_result(FromExploded(false, exploded, &time)); | |
527 return time; | |
524 } | 528 } |
525 static Time FromLocalExploded(const Exploded& exploded) { | 529 static Time FromLocalExploded(const Exploded& exploded) { |
526 return FromExploded(true, exploded); | 530 base::Time time; |
531 ignore_result(FromExploded(true, exploded, &time)); | |
532 return time; | |
533 } | |
534 | |
535 // Converts an exploded structure representing either the local time or UTC | |
536 // into a Time class. This is a transition to a new format, where the | |
537 // converted time is set to |time| and FromUTCExploded, FromLocalExploded and | |
538 // FromExploded return true on success or false on failure. For example, | |
mmenke
2016/05/24 16:08:33
Think your second sentence shouldn't refer to the
maksims (do not use this acc)
2016/05/26 04:38:18
Done.
| |
539 // FromExploded can fail when 31st of a month is set on a 28-30 day month, | |
540 // which results in 1st day of the next month. | |
541 static bool FromUTCExploded(const Exploded& exploded, | |
542 Time* time) WARN_UNUSED_RESULT { | |
543 return FromExploded(false, exploded, time); | |
544 } | |
545 static bool FromLocalExploded(const Exploded& exploded, | |
546 Time* time) WARN_UNUSED_RESULT { | |
547 return FromExploded(true, exploded, time); | |
527 } | 548 } |
528 | 549 |
529 // Converts a string representation of time to a Time object. | 550 // Converts a string representation of time to a Time object. |
530 // An example of a time string which is converted is as below:- | 551 // An example of a time string which is converted is as below:- |
531 // "Tue, 15 Nov 1994 12:45:26 GMT". If the timezone is not specified | 552 // "Tue, 15 Nov 1994 12:45:26 GMT". If the timezone is not specified |
532 // in the input string, FromString assumes local time and FromUTCString | 553 // in the input string, FromString assumes local time and FromUTCString |
533 // assumes UTC. A timezone that cannot be parsed (e.g. "UTC" which is not | 554 // assumes UTC. A timezone that cannot be parsed (e.g. "UTC" which is not |
534 // specified in RFC822) is treated as if the timezone is not specified. | 555 // specified in RFC822) is treated as if the timezone is not specified. |
535 // TODO(iyengar) Move the FromString/FromTimeT/ToTimeT/FromFileTime to | 556 // TODO(iyengar) Move the FromString/FromTimeT/ToTimeT/FromFileTime to |
536 // a new time converter class. | 557 // a new time converter class. |
(...skipping 20 matching lines...) Expand all Loading... | |
557 private: | 578 private: |
558 friend class time_internal::TimeBase<Time>; | 579 friend class time_internal::TimeBase<Time>; |
559 | 580 |
560 explicit Time(int64_t us) : TimeBase(us) {} | 581 explicit Time(int64_t us) : TimeBase(us) {} |
561 | 582 |
562 // Explodes the given time to either local time |is_local = true| or UTC | 583 // Explodes the given time to either local time |is_local = true| or UTC |
563 // |is_local = false|. | 584 // |is_local = false|. |
564 void Explode(bool is_local, Exploded* exploded) const; | 585 void Explode(bool is_local, Exploded* exploded) const; |
565 | 586 |
566 // Unexplodes a given time assuming the source is either local time | 587 // Unexplodes a given time assuming the source is either local time |
567 // |is_local = true| or UTC |is_local = false|. | 588 // |is_local = true| or UTC |is_local = false|. Function returns false on |
568 static Time FromExploded(bool is_local, const Exploded& exploded); | 589 // failure and sets |time| to Time(0). Otherwise returns true and sets |time| |
590 // to non-exploded time. | |
591 static bool FromExploded(bool is_local, | |
592 const Exploded& exploded, | |
593 Time* time) WARN_UNUSED_RESULT; | |
569 | 594 |
570 // Converts a string representation of time to a Time object. | 595 // Converts a string representation of time to a Time object. |
571 // An example of a time string which is converted is as below:- | 596 // An example of a time string which is converted is as below:- |
572 // "Tue, 15 Nov 1994 12:45:26 GMT". If the timezone is not specified | 597 // "Tue, 15 Nov 1994 12:45:26 GMT". If the timezone is not specified |
573 // in the input string, local time |is_local = true| or | 598 // in the input string, local time |is_local = true| or |
574 // UTC |is_local = false| is assumed. A timezone that cannot be parsed | 599 // UTC |is_local = false| is assumed. A timezone that cannot be parsed |
575 // (e.g. "UTC" which is not specified in RFC822) is treated as if the | 600 // (e.g. "UTC" which is not specified in RFC822) is treated as if the |
576 // timezone is not specified. | 601 // timezone is not specified. |
577 static bool FromStringInternal(const char* time_string, | 602 static bool FromStringInternal(const char* time_string, |
578 bool is_local, | 603 bool is_local, |
(...skipping 210 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
789 static void WaitUntilInitializedWin(); | 814 static void WaitUntilInitializedWin(); |
790 #endif | 815 #endif |
791 }; | 816 }; |
792 | 817 |
793 // For logging use only. | 818 // For logging use only. |
794 BASE_EXPORT std::ostream& operator<<(std::ostream& os, ThreadTicks time_ticks); | 819 BASE_EXPORT std::ostream& operator<<(std::ostream& os, ThreadTicks time_ticks); |
795 | 820 |
796 } // namespace base | 821 } // namespace base |
797 | 822 |
798 #endif // BASE_TIME_TIME_H_ | 823 #endif // BASE_TIME_TIME_H_ |
OLD | NEW |