Skip to content

Commit

Permalink
+ Added tz::delay::elapsed()
Browse files Browse the repository at this point in the history
  • Loading branch information
harrand committed Feb 3, 2023
1 parent 5949667 commit c7129ac
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/tz/core/time.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,12 @@ namespace tz

bool delay::done() const
{
return (this->begin_systime + this->delay_length) <= system_time();
return this->elapsed() >= this->delay_length;
}

duration delay::elapsed() const
{
return this->begin_systime - system_time();
}

void delay::reset()
Expand Down
4 changes: 4 additions & 0 deletions src/tz/core/time.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,10 @@ namespace tz
* Query as to whether the delay length has passed since construction of the delay object.
*/
bool done() const;
/**
* Retrieve how much time has passed since the delay began. If the elapsed time is longer than or equal to the delay length, the delay is `done()`.
*/
duration elapsed() const;
/**
* Reset the delay object. The instant a delay object is reset, 0 seconds have elapsed since the "construction" of the object. You can use this to check for the same delay again in the future.
*/
Expand Down

0 comments on commit c7129ac

Please sign in to comment.