summaryrefslogtreecommitdiffhomepage
path: root/src/timer.hpp
diff options
context:
space:
mode:
authorStanislaw Halik <sthalik@misaki.pl>2024-03-01 12:56:43 +0100
committerStanislaw Halik <sthalik@misaki.pl>2024-03-01 12:56:43 +0100
commit03f6789a7f5360290a11899b4961bc083d04092a (patch)
tree9a62f8031025c6458b9aca4aabb90d65d50effe3 /src/timer.hpp
parentb204d90b324fa00a1ed1c6cf2a0ba05c25e73407 (diff)
w
Diffstat (limited to 'src/timer.hpp')
-rw-r--r--src/timer.hpp44
1 files changed, 42 insertions, 2 deletions
diff --git a/src/timer.hpp b/src/timer.hpp
index d9b0f602..24818722 100644
--- a/src/timer.hpp
+++ b/src/timer.hpp
@@ -1,9 +1,49 @@
#pragma once
-#include "timer-fwd.hpp"
-#include <mg/Time.h> // todo! replace with my own
+#include <compare>
namespace floormat {
+struct Ns;
+
+struct Ns
+{
+ friend Ns operator+(const Ns& lhs, const Ns& rhs);
+ friend Ns operator-(const Ns& lhs, const Ns& rhs);
+ friend uint64_t operator/(const Ns& lhs, const Ns& rhs);
+ friend Ns operator%(const Ns& lhs, const Ns& rhs);
+
+ friend bool operator==(const Ns& lhs, const Ns& rhs);
+ friend std::strong_ordering operator<=>(const Ns& lhs, const Ns& rhs);
+
+ explicit operator uint64_t() const;
+ explicit operator float() const;
+ uint64_t operator*() const;
+
+ uint64_t stamp;
+ static constexpr uint64_t Min = 0, Max = (uint64_t)-1;
+ static constexpr uint64_t Second = 1000000000, Millisecond = 1000000;
+
+ explicit constexpr Ns(): stamp{0} {}
+ explicit constexpr Ns(uint64_t x) : stamp{x} {}
+};
+
+struct Time final
+{
+ static Time now() noexcept;
+ bool operator==(const Time&) const noexcept;
+ std::strong_ordering operator<=>(const Time&) const noexcept;
+ friend Ns operator-(const Time& a, const Time& b) noexcept;
+ [[nodiscard]] Ns update(const Time& ts = now()) & noexcept;
+
+ static float to_seconds(const Ns& ts) noexcept;
+ static float to_milliseconds(const Ns& ts) noexcept;
+
+ uint64_t stamp = init();
+
+private:
+ static uint64_t init() noexcept;
+};
+
constexpr inline size_t fm_DATETIME_BUF_SIZE = 32;
const char* format_datetime_to_string(char(&buf)[fm_DATETIME_BUF_SIZE]);