I try to have my program figure if an event is getting reached during the day
for instance, I want to be able to create events at 10:00:00 so that a task gets executed at that moment in the day (only once)
so I have this function that can tell the time has passed, but it will always return true after 10:00 (time parameter)
bool Tools::passedTimeToday(std::time_t time)
{
auto now = std::chrono::system_clock::now();
std::time_t _now = std::chrono::system_clock::to_time_t(now);
if (std::difftime(_now,time)<0)
return false;
else
return true;
}
how do I check the time has passed only once ?
do I use some sort of epsilon around that time ? what value shoud I use for that epsilon ?
double delta = std::difftime(_now,time);
if ( (delta<0) && (delta>-epsilon) )
{
...
I mean it could work, but what if my program tests that condition too late (bigger than epsilon) ?
I thought about using a boolean flag instead (bool processed), but then evey time I run the program, it would also run all tasks that happened around that time
any help appreciated
thanks