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 8 #include <chrono> 9 10 #include "platform/base/trivial_clock_traits.h" 11 12 namespace openscreen { 13 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 { 23 public: 24 // Returns the current time. 25 static time_point now() noexcept; 26 }; 27 28 // Returns the number of seconds since UNIX epoch (1 Jan 1970, midnight) 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." 33 std::chrono::seconds GetWallTimeSinceUnixEpoch() noexcept; 34 35 } // namespace openscreen 36 37 #endif // PLATFORM_API_TIME_H_ 38