Well, I wrote you up a rather long reply, and the forum said "Your message can't be posted because you've re-registered since loading that page. Click the back arrow of your browser and reload the page."
Which naturally erased my post.
In a thumbnail, I believe some of these factors are going to have to be worked out on your program, after it's up and running correctly with most of the situations.
This is my suggestion:
I would try to change everything into integers, instead of "time" or floats, as early in the process, as possible.
Solving it may be as simple as using a for loop - starting with the motor_start_time, and ending with the motor_start time + band_period (mst + bp)
Code:
startFlag = 0;
for(i = mst, midnightFlag = 0; i <= (mst+bp); i++) {
/* if i == 2400, then it's a midnight X over event. For this calculation,
increment present_time by 2400;
*/
if(i == 2400) {
present_time += 2400;
midnightFlag = 1;
}
if(i == present_time) //which is now an integer
startFlag = 1;
}
if(midnightFlag)
present_time -= 2400;
if(startFlag == 1)
//start the motor