mark a. foltz | c28ca40 | 2018-07-19 16:11:32 -0700 | [diff] [blame] | 1 | // Copyright 2018 The Chromium Authors. All rights reserved. |
| 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | #ifndef PLATFORM_API_TIME_H_ |
| 6 | #define PLATFORM_API_TIME_H_ |
| 7 | |
Yuri Wiitala | eb8eee7 | 2019-03-26 15:52:43 -0700 | [diff] [blame] | 8 | #include <chrono> |
Yuri Wiitala | f162a61 | 2019-11-22 22:46:04 -0800 | [diff] [blame] | 9 | |
| 10 | #include "platform/base/trivial_clock_traits.h" |
mark a. foltz | c28ca40 | 2018-07-19 16:11:32 -0700 | [diff] [blame] | 11 | |
| 12 | namespace openscreen { |
mark a. foltz | c28ca40 | 2018-07-19 16:11:32 -0700 | [diff] [blame] | 13 | |
Yuri Wiitala | f162a61 | 2019-11-22 22:46:04 -0800 | [diff] [blame] | 14 | // The "reasonably high-resolution" source of monotonic time from the embedder, |
| 15 | // exhibiting the traits described in TrivialClockTraits. This class is not |
| 16 | // instantiated. It only contains a static now() function. |
| 17 | // |
| 18 | // For example, the default platform implementation bases this on |
| 19 | // std::chrono::steady_clock or std::chrono::high_resolution_clock, but an |
| 20 | // embedder may choose to use a different source of time (e.g., the embedder's |
| 21 | // time library, a simulated time source, or a mock). |
| 22 | class Clock : public TrivialClockTraits { |
btolsch | 5292c94 | 2018-07-26 00:06:22 -0700 | [diff] [blame] | 23 | public: |
Yuri Wiitala | f162a61 | 2019-11-22 22:46:04 -0800 | [diff] [blame] | 24 | // Returns the current time. |
Yuri Wiitala | eb8eee7 | 2019-03-26 15:52:43 -0700 | [diff] [blame] | 25 | static time_point now() noexcept; |
btolsch | 5292c94 | 2018-07-26 00:06:22 -0700 | [diff] [blame] | 26 | }; |
| 27 | |
Yuri Wiitala | eb8eee7 | 2019-03-26 15:52:43 -0700 | [diff] [blame] | 28 | // Returns the number of seconds since UNIX epoch (1 Jan 1970, midnight) |
Yuri Wiitala | f162a61 | 2019-11-22 22:46:04 -0800 | [diff] [blame] | 29 | // according to the wall clock, which is subject to adjustments (e.g., via NTP). |
| 30 | // Note that this is NOT necessarily the same time source as Clock::now() above, |
| 31 | // and is NOT guaranteed to be monotonically non-decreasing; it is "calendar |
| 32 | // time." |
Jordan Bayles | c9201dd | 2020-06-02 15:51:31 -0700 | [diff] [blame^] | 33 | std::chrono::seconds GetWallTimeSinceUnixEpoch() noexcept; |
mark a. foltz | c28ca40 | 2018-07-19 16:11:32 -0700 | [diff] [blame] | 34 | |
mark a. foltz | c28ca40 | 2018-07-19 16:11:32 -0700 | [diff] [blame] | 35 | } // namespace openscreen |
| 36 | |
btolsch | a21e8ed | 2018-08-30 15:13:48 -0700 | [diff] [blame] | 37 | #endif // PLATFORM_API_TIME_H_ |