From 2401786b582acf579ec4811549c3eeef8471e01e Mon Sep 17 00:00:00 2001 From: BartolomeyKant Date: Wed, 1 Apr 2026 14:37:42 +0500 Subject: [PATCH] fix uap time interval --- aether/clock.h | 15 ++++++--------- aether/uap/uap.cpp | 14 +++++--------- aether/uap/uap.h | 4 ++-- 3 files changed, 13 insertions(+), 20 deletions(-) diff --git a/aether/clock.h b/aether/clock.h index 69cd231d..5f8940ad 100644 --- a/aether/clock.h +++ b/aether/clock.h @@ -48,15 +48,9 @@ class SyncClock { return time_point{ChronoClock::now().time_since_epoch() + SyncTimeDiff}; } - /** - * \brief Return sync time - */ - template - static std::enable_if_t || - std::is_same_v, - time_point> - sync_time(std::chrono::time_point const& tp) { - return time_point{tp.time_since_epoch() + SyncTimeDiff}; + static auto ToRawTime(time_point tp) { + return + typename ChronoClock::time_point{tp.time_since_epoch() - SyncTimeDiff}; } }; @@ -85,6 +79,9 @@ using SyncTimePoint = typename SyncClock::time_point; inline auto Now() { return SystemClock::now(); } // synchronised time inline auto SyncTime() { return SyncClock::now(); } + +inline auto ToRawTime(SyncTimePoint tp) { return SyncClock::ToRawTime(tp); } + } // namespace ae #endif // AETHER_CLOCK_H_ diff --git a/aether/uap/uap.cpp b/aether/uap/uap.cpp index 3311d9e3..cc180f42 100644 --- a/aether/uap/uap.cpp +++ b/aether/uap/uap.cpp @@ -27,17 +27,12 @@ namespace ae { Duration Uap::IntervalState::remaining() const { auto interval_end = until(); - auto current_time = SyncTime(); + auto current_time = Now(); auto diff = interval_end - current_time; - AE_TELED_DEBUG( - "Calculate remaining end {:%Y-%m-%d %H:%M:%S} current {:%Y-%m-%d " - "%H:%M:%S} diff {:%S}", - interval_end, current_time, diff); - return std::chrono::duration_cast(diff); } -SyncTimePoint Uap::IntervalState::until() const { return end_time; } +TimePoint Uap::IntervalState::until() const { return end_time; } Uap::Timer::Timer(Uap::ptr uap) : uap_{std::move(uap)} {} @@ -118,7 +113,7 @@ Uap::IntervalState Uap::UpdateInterval(Duration time_offset) { AE_TELED_DEBUG( "Update interval\n start_time {:%Y-%m-%d %H:%M:%S}\n current_time " "{:%Y-%m-%d %H:%M:%S}\n interval_duration {:%H:%M:%S}\n time_elapsed " - "{}", + "{:%H:%M:%S}", start_time_, current_time, interval_duration, time_elapsed); if (time_elapsed > interval_duration) { @@ -160,7 +155,8 @@ Uap::IntervalState Uap::UpdateInterval(Duration time_offset) { current_interval_index_, next_interval_index_, start_time_, current_time); return IntervalState{ .interval = intervals_[current_interval_index_], - .end_time = start_time_ + intervals_[current_interval_index_].duration, + .end_time = + ToRawTime(start_time_ + intervals_[current_interval_index_].duration), }; } diff --git a/aether/uap/uap.h b/aether/uap/uap.h index fb293452..3441bbb3 100644 --- a/aether/uap/uap.h +++ b/aether/uap/uap.h @@ -69,10 +69,10 @@ class Uap final : public Obj { struct IntervalState { Interval interval; - SyncTimePoint end_time; + TimePoint end_time; Duration remaining() const; - SyncTimePoint until() const; + TimePoint until() const; }; public: