I need to execute a function once, at certain times of the day, like this pseudo code:
while(true)
{
now = Now();
if(now == 16:00 or now == 22:00)
{
call_function();
}
}
I do use chrono
Timepoints quote often, but always for relative arithmetic comparisons like this:
if(now >= prev_ts + std::chrono::minutes(30))
{
// do something
prev_ts = now;
and this won’t work because the first invoccation will be immediately, whereas I need it to happen at the next 16:00.
What is the cleanest way to achieve this using C++23?
What’s confusing me is I don’t care about dates, nor do I care about offsets. I want something which is just a time object, not a datetime.