basically I need a time switch in C. I get the current date and time using strftime. So at the end I have the information as a string.
For the time switch I only need to compare hours and minutes. So in pseudocode e.g.:
static bool isSwitchedOn = false;
if(timeOfDay>timeToSwitchOn && !isSwitchedOn) {
switchOn();
isSwitchedOn = true;
}
else if(timeOfDay>=timeToSwitchOf && isSwitchedOn) {
switchOff();
isSwitchedOn = false;
}
One solution would be to use atoi to convert all the times to int and then compare hours and minutes separate.
I saw that I could maybe use difftime, but this requires also a date and I would like not to use dates at all. So and because I already have the times this question is not a duplicate of How do I measure time in C?
EDIT: Sorry, I was not clear enough. I do not have date information available for the time I compare the current time with. It is more like on every day at time 20:33 turn on and 20:55 turn off.
Is there a better solution?
Thanks