I am working on a project for the Pebble platform. Apps are written in C, and my question is not specific to that platform.
The Pebble API has a Struct called PblTm that is populated every second by a line of code. My goal is to compare the struct with the current time. I have created PblTm structs and populated them with the times I need to compare against. I only care about the hour and minute sections of the structs. So far, I have the following code.
bool comp_time(int h1, int m1, int h2, int m2, int h3, int m3) {
if((h1<=h2) && (h2<=h3)) //Is start hour <= now hour <= end hour?
{
if((h1=h2) && (m2>=m1)) //If start hour = now hour, is now min >= start min ?
{
return true;
}
if((h2=h3) && (m2<=m3)) //If end hour = now hour, if now min <= end min?
{
return true;
}
if((h1>h2) && (h2<h3)) //If start hour < now hour < end hour?
{
return true;
}
}
else
{
return false;
}
return false;
}
I initially tried to feed the structs themselves as parameter to the function something like:
comp_time(&first_start,&now,&first_end);
And then referenced the elements of the struct inside the function, I could never get that to compile, and I couldn't find information on it. (I may have not have been searching for the correct terms).
I then changed to feeding the int parameters to the function itself like this:
comp_time(first_start.tm_hour,first_start.tm_min,now.tm_hour,now.tm_min,first_end.tm_hour,first_end.tm_min)
It is a quite clumsy way of doing it, but I have already done the work to type it all out. My main problem however, is that the comparison function doesn't function. It returns (apparently randomly, I have not been able to find a pattern) true for values that do not fit and false for some that fit.
Do you have any ideas?