blob: 7756d63af6296ea68d782e0737760189b22d03a4 [file] [log] [blame]
// Copyright 2018 The Fuchsia Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include <lib/zx/time.h>
namespace timekeeper {
// Abstraction over the clock.
// This class allows to retrieve the current time for any supported clock id.
// This being a class, it allows to inject custom behavior for tests.
class Clock {
Clock() = default;
virtual ~Clock() = default;
Clock(const Clock&) = delete;
Clock& operator=(const Clock&) = delete;
// Returns the current UTC time.
zx_status_t UtcNow(zx::time_utc* result) const {
zx_time_t time;
zx_status_t status = GetUtcTime(&time);
*result = zx::time_utc(time);
return status;
// Returns the current monotonic time. See |zx_clock_get_monotonic|.
zx::time Now() const { return zx::time(GetMonotonicTime()); }
// Returns the current UTC time.
virtual zx_status_t GetUtcTime(zx_time_t* time) const = 0;
// Returns the current monotonic time. See |zx_clock_get_monotonic|.
virtual zx_time_t GetMonotonicTime() const = 0;
} // namespace timekeeper