Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 6 additions & 9 deletions aether/clock.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,15 +48,9 @@ class SyncClock {
return time_point{ChronoClock::now().time_since_epoch() + SyncTimeDiff};
}

/**
* \brief Return sync time
*/
template <typename C, typename D>
static std::enable_if_t<std::is_same_v<SyncClock, C> ||
std::is_same_v<internal_clock, C>,
time_point>
sync_time(std::chrono::time_point<C, D> 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};
}
};

Expand Down Expand Up @@ -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_
14 changes: 5 additions & 9 deletions aether/uap/uap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<Duration>(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)} {}

Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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),
};
}

Expand Down
4 changes: 2 additions & 2 deletions aether/uap/uap.h
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
Loading