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 561 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
572 // "Tue, 15 Nov 1994 12:45:26 GMT". If the timezone is not specified | 572 // "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 | 573 // in the input string, local time |is_local = true| or |
574 // UTC |is_local = false| is assumed. A timezone that cannot be parsed | 574 // 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 | 575 // (e.g. "UTC" which is not specified in RFC822) is treated as if the |
576 // timezone is not specified. | 576 // timezone is not specified. |
577 static bool FromStringInternal(const char* time_string, | 577 static bool FromStringInternal(const char* time_string, |
578 bool is_local, | 578 bool is_local, |
579 Time* parsed_time); | 579 Time* parsed_time); |
580 }; | 580 }; |
581 | 581 |
582 // Inline the TimeDelta factory methods, for fast TimeDelta construction. | |
583 | |
584 // static | 582 // static |
585 constexpr inline TimeDelta TimeDelta::FromDays(int days) { | 583 constexpr TimeDelta TimeDelta::FromDays(int days) { |
586 return days == std::numeric_limits<int>::max() | 584 return days == std::numeric_limits<int>::max() |
587 ? Max() | 585 ? Max() |
588 : TimeDelta(days * Time::kMicrosecondsPerDay); | 586 : TimeDelta(days * Time::kMicrosecondsPerDay); |
589 } | 587 } |
590 | 588 |
591 // static | 589 // static |
592 constexpr inline TimeDelta TimeDelta::FromHours(int hours) { | 590 constexpr TimeDelta TimeDelta::FromHours(int hours) { |
593 return hours == std::numeric_limits<int>::max() | 591 return hours == std::numeric_limits<int>::max() |
594 ? Max() | 592 ? Max() |
595 : TimeDelta(hours * Time::kMicrosecondsPerHour); | 593 : TimeDelta(hours * Time::kMicrosecondsPerHour); |
596 } | 594 } |
597 | 595 |
598 // static | 596 // static |
599 constexpr inline TimeDelta TimeDelta::FromMinutes(int minutes) { | 597 constexpr TimeDelta TimeDelta::FromMinutes(int minutes) { |
600 return minutes == std::numeric_limits<int>::max() | 598 return minutes == std::numeric_limits<int>::max() |
601 ? Max() | 599 ? Max() |
602 : TimeDelta(minutes * Time::kMicrosecondsPerMinute); | 600 : TimeDelta(minutes * Time::kMicrosecondsPerMinute); |
603 } | 601 } |
604 | 602 |
605 // static | 603 // static |
606 constexpr inline TimeDelta TimeDelta::FromSeconds(int64_t secs) { | 604 constexpr TimeDelta TimeDelta::FromSeconds(int64_t secs) { |
607 return FromProduct(secs, Time::kMicrosecondsPerSecond); | 605 return FromProduct(secs, Time::kMicrosecondsPerSecond); |
608 } | 606 } |
609 | 607 |
610 // static | 608 // static |
611 constexpr inline TimeDelta TimeDelta::FromMilliseconds(int64_t ms) { | 609 constexpr TimeDelta TimeDelta::FromMilliseconds(int64_t ms) { |
612 return FromProduct(ms, Time::kMicrosecondsPerMillisecond); | 610 return FromProduct(ms, Time::kMicrosecondsPerMillisecond); |
613 } | 611 } |
614 | 612 |
615 // static | 613 // static |
616 constexpr inline TimeDelta TimeDelta::FromSecondsD(double secs) { | 614 constexpr TimeDelta TimeDelta::FromSecondsD(double secs) { |
617 return FromDouble(secs * Time::kMicrosecondsPerSecond); | 615 return FromDouble(secs * Time::kMicrosecondsPerSecond); |
618 } | 616 } |
619 | 617 |
620 // static | 618 // static |
621 constexpr inline TimeDelta TimeDelta::FromMillisecondsD(double ms) { | 619 constexpr TimeDelta TimeDelta::FromMillisecondsD(double ms) { |
622 return FromDouble(ms * Time::kMicrosecondsPerMillisecond); | 620 return FromDouble(ms * Time::kMicrosecondsPerMillisecond); |
623 } | 621 } |
624 | 622 |
625 // static | 623 // static |
626 constexpr inline TimeDelta TimeDelta::FromMicroseconds(int64_t us) { | 624 constexpr TimeDelta TimeDelta::FromMicroseconds(int64_t us) { |
627 return TimeDelta(us); | 625 return TimeDelta(us); |
628 } | 626 } |
629 | 627 |
630 // static | 628 // static |
631 constexpr inline TimeDelta TimeDelta::FromDouble(double value) { | 629 constexpr TimeDelta TimeDelta::FromDouble(double value) { |
632 // TODO(crbug.com/612601): Use saturated_cast<int64_t>(value) once we sort out | 630 // TODO(crbug.com/612601): Use saturated_cast<int64_t>(value) once we sort out |
633 // the Min() behavior. | 631 // the Min() behavior. |
634 return value > std::numeric_limits<int64_t>::max() | 632 return value > std::numeric_limits<int64_t>::max() |
635 ? Max() | 633 ? Max() |
636 : value < -std::numeric_limits<int64_t>::max() | 634 : value < -std::numeric_limits<int64_t>::max() |
637 ? -Max() | 635 ? -Max() |
638 : TimeDelta(static_cast<int64_t>(value)); | 636 : TimeDelta(static_cast<int64_t>(value)); |
639 } | 637 } |
640 | 638 |
641 // static | 639 // static |
642 constexpr inline TimeDelta TimeDelta::FromProduct(int64_t value, | 640 constexpr TimeDelta TimeDelta::FromProduct(int64_t value, |
643 int64_t positive_value) { | 641 int64_t positive_value) { |
644 return (DCHECK(positive_value > 0), | 642 return (DCHECK(positive_value > 0), |
645 value > std::numeric_limits<int64_t>::max() / positive_value | 643 value > std::numeric_limits<int64_t>::max() / positive_value |
646 ? Max() | 644 ? Max() |
647 : value < -std::numeric_limits<int64_t>::max() / positive_value | 645 : value < -std::numeric_limits<int64_t>::max() / positive_value |
648 ? -Max() | 646 ? -Max() |
649 : TimeDelta(value * positive_value)); | 647 : TimeDelta(value * positive_value)); |
650 } | 648 } |
651 | 649 |
652 // For logging use only. | 650 // For logging use only. |
653 BASE_EXPORT std::ostream& operator<<(std::ostream& os, Time time); | 651 BASE_EXPORT std::ostream& operator<<(std::ostream& os, Time time); |
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
791 static void WaitUntilInitializedWin(); | 789 static void WaitUntilInitializedWin(); |
792 #endif | 790 #endif |
793 }; | 791 }; |
794 | 792 |
795 // For logging use only. | 793 // For logging use only. |
796 BASE_EXPORT std::ostream& operator<<(std::ostream& os, ThreadTicks time_ticks); | 794 BASE_EXPORT std::ostream& operator<<(std::ostream& os, ThreadTicks time_ticks); |
797 | 795 |
798 } // namespace base | 796 } // namespace base |
799 | 797 |
800 #endif // BASE_TIME_TIME_H_ | 798 #endif // BASE_TIME_TIME_H_ |
OLD | NEW |