blob: af0dda7573d72721e72ecb62d7e4da70b5d53dc7 [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 {
13namespace platform {
14
Yuri Wiitalaf162a612019-11-22 22:46:04 -080015// The "reasonably high-resolution" source of monotonic time from the embedder,
16// exhibiting the traits described in TrivialClockTraits. This class is not
17// instantiated. It only contains a static now() function.
18//
19// For example, the default platform implementation bases this on
20// std::chrono::steady_clock or std::chrono::high_resolution_clock, but an
21// embedder may choose to use a different source of time (e.g., the embedder's
22// time library, a simulated time source, or a mock).
23class Clock : public TrivialClockTraits {
btolsch5292c942018-07-26 00:06:22 -070024 public:
Yuri Wiitalaf162a612019-11-22 22:46:04 -080025 // Returns the current time.
Yuri Wiitalaeb8eee72019-03-26 15:52:43 -070026 static time_point now() noexcept;
btolsch5292c942018-07-26 00:06:22 -070027};
28
Yuri Wiitalaeb8eee72019-03-26 15:52:43 -070029// Returns the number of seconds since UNIX epoch (1 Jan 1970, midnight)
Yuri Wiitalaf162a612019-11-22 22:46:04 -080030// according to the wall clock, which is subject to adjustments (e.g., via NTP).
31// Note that this is NOT necessarily the same time source as Clock::now() above,
32// and is NOT guaranteed to be monotonically non-decreasing; it is "calendar
33// time."
Yuri Wiitalaeb8eee72019-03-26 15:52:43 -070034std::chrono::seconds GetWallTimeSinceUnixEpoch() noexcept;
mark a. foltzc28ca402018-07-19 16:11:32 -070035
36} // namespace platform
37} // namespace openscreen
38
btolscha21e8ed2018-08-30 15:13:48 -070039#endif // PLATFORM_API_TIME_H_