tetl 0.1.0
Embedded Template Library
Loading...
Searching...
No Matches
system_clock.hpp
Go to the documentation of this file.
1// SPDX-License-Identifier: BSL-1.0
2// SPDX-FileCopyrightText: Copyright (C) 2023 Tobias Hienzsch
3
4#ifndef TETL_CHRONO_SYSTEM_CLOCK_HPP
5#define TETL_CHRONO_SYSTEM_CLOCK_HPP
6
7#include <etl/_chrono/duration.hpp>
8#include <etl/_chrono/duration_cast.hpp>
9#include <etl/_cstdint/int_t.hpp>
10#include <etl/_ctime/time_t.hpp>
11#include <etl/_ratio/ratio.hpp>
12
13namespace etl::chrono {
14
15/// \ingroup chrono
17 using rep = int32_t;
18 using period = micro;
19 using duration = chrono::duration<rep, period>;
21 static constexpr bool is_steady = false;
22
23 [[nodiscard]] static auto now() noexcept -> time_point
24 {
25 return {};
26 }
27
28 [[nodiscard]] static auto to_time_t(time_point const& t) noexcept -> time_t
29 {
30 return static_cast<time_t>(duration_cast<seconds>(t.time_since_epoch()).count());
31 }
32
33 [[nodiscard]] static auto from_time_t(time_t t) noexcept -> time_point
34 {
35 return time_point{seconds{static_cast<seconds::rep>(t)}};
36 }
37};
38
39template <typename Duration>
41
44
45} // namespace etl::chrono
46
47#endif // TETL_CHRONO_SYSTEM_CLOCK_HPP
Definition abs.hpp:12
Definition adjacent_find.hpp:9
Class template etl::chrono::duration represents a time interval.
Definition duration.hpp:32
Definition system_clock.hpp:16
static auto now() noexcept -> time_point
Definition system_clock.hpp:23
static auto from_time_t(time_t t) noexcept -> time_point
Definition system_clock.hpp:33
static constexpr bool is_steady
Definition system_clock.hpp:21
static auto to_time_t(time_point const &t) noexcept -> time_t
Definition system_clock.hpp:28