blob: dcf24accc88eafebf4753cdedb4ef0e8dd96d7f2 [file] [log] [blame]
mark a. foltzc28ca402018-07-19 16:11:32 -07001// 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 Wiitalaeb8eee72019-03-26 15:52:43 -07008#include <chrono>
Yuri Wiitalaf162a612019-11-22 22:46:04 -08009
10#include "platform/base/trivial_clock_traits.h"
mark a. foltzc28ca402018-07-19 16:11:32 -070011
12namespace openscreen {
mark a. foltzc28ca402018-07-19 16:11:32 -070013
Yuri Wiitalaf162a612019-11-22 22:46:04 -080014// 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).
22class Clock : public TrivialClockTraits {
btolsch5292c942018-07-26 00:06:22 -070023 public:
Yuri Wiitalaf162a612019-11-22 22:46:04 -080024 // Returns the current time.
Yuri Wiitalaeb8eee72019-03-26 15:52:43 -070025 static time_point now() noexcept;
btolsch5292c942018-07-26 00:06:22 -070026};
27
Yuri Wiitalaeb8eee72019-03-26 15:52:43 -070028// Returns the number of seconds since UNIX epoch (1 Jan 1970, midnight)
Yuri Wiitalaf162a612019-11-22 22:46:04 -080029// 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 Baylesc9201dd2020-06-02 15:51:31 -070033std::chrono::seconds GetWallTimeSinceUnixEpoch() noexcept;
mark a. foltzc28ca402018-07-19 16:11:32 -070034
mark a. foltzc28ca402018-07-19 16:11:32 -070035} // namespace openscreen
36
btolscha21e8ed2018-08-30 15:13:48 -070037#endif // PLATFORM_API_TIME_H_