comparison in a time sequence
Here is the basic idea and a sample implementation for solving the problem:

The problem is: Given a start time time1 and a period period, each described by a pair of (hour,minute), how can we check whether another time time2 is within time1 to time1 + period?

First we can see that we given a (hour, minute) pair we can compute the total number of minutes as totalMinutes = 60*hour + minute. 

Then we can observe that there two distinct cases that we must check:


the entire "time check period", that is, time1 to time1 + period is within 00:00 to 24:00 without overflowing past 24:00 when we simply add the times. then, we can use a simple bounds check worded as "time2 must be greater than time1 and less or equal to time1 + period when comparing total minnutes.
time1 + period overflows past 24:00. We consider an example of  time1= 20:00 and period = 8:00. Thus all valid times are from 20:00 to 04:00 with an implicit "wrap around" at 24:00 to 00:00. We can see that there are now two time-intervals we must check: Everything from 20:01 to 24:00 and from 00:00 to 04:00 is valid. Thus we can derive the the bounds in minutes again. We can obtain the 04:00 by computing 20:00 + 08:00 modulo 24:00. The C operator % is used to compute the residue of the division by a certain number. I.e. 28 % 24 = 4 because 28 / 24 = 1 residue 4. This is  called modulo-arithmetic.


The following C++ program demonstrates the solution:

#include &lt;cstdio&gt;

/* returns whether time2 defined by hour2:minute2 is within the period time1 = hour1:minute1 to time1 + period. */
bool is_time_within_period(
    int hour1, int minute1, 
    int hour2, int minute2,
    int periodHour, int periodMinute) {

        //Reject garbage input
        if(hour1 &gt; 24 || hour2 &gt; 24 
            || minute1 &gt; 60 || minute2 &gt; 60
            || periodHour &gt; 24 || periodMinute &gt; 60) {
                //TODO throw error message
                return false;
        }

        //Convert hours and minutes into absolute minutes. One hour is 60 minutes.
        int time1Minutes = 60 * hour1  + minute1;
        int periodMinutes = 60 * periodHour + periodMinute;
        int time2Minutes  = 60 * hour2 + minute2;

        int periodEnd = time1Minutes + periodMinutes;

        //If the start time plus the period time is over 24:00 there is a wrap-around the we need to consider.
        bool wrapAround = false;
        if( periodEnd &gt; (24 * 60)) {
            wrapAround = true;
        }

        bool result = false;

        //printf("Wrap: %d Period end %d\n", wrapAround, periodEnd);

        if(!wrapAround) {
            //if there is no wrap-around we can just compare the total minutes against each other
            //time1 must be after time2 but before (time1 + period).
            result = time2Minutes &lt;= (time1Minutes + periodMinutes) &amp;&amp; time2Minutes &gt; time1Minutes;
        } else {
            //There was a wrap around, i.e. start time + period was beyond 24:00.
            //We need to make two comparisons: is it in the time period from time1Minutes to 24:00?
            result = time1Minutes &lt; time2Minutes &amp;&amp; time2Minutes &lt;= (24 * 60);

            //the result can also be okay if it from the time from 00:00 to the remaining period
            //use the module operator here. This transforms e.g. 28:00 would be reduced to 04:00. (modulo 24 hours calculated in minutes)
            int upper = (periodEnd % (24 * 60));
            //printf("Upper: %d (%02d:%02d)\n", upper, (upper / 60), upper % 60);
            result |= time2Minutes &gt;= 0 &amp;&amp; time2Minutes &lt;= upper;
        }

        return result;
}

int main() {

    const int hourStart = 20;
    const int minuteStart = 0;

    const int periodHours = 8;
    const int periodMinutes = 0;

    //play around with these values
    const int compareTimeHour  = 4;
    const int compareTimeMinute = 0;

    printf("Start: %02d:%02d\n", hourStart, minuteStart);
    printf("Period: %02d:%02d\n", periodHours, periodMinutes);
    printf("Check time: %02d:%02d\n", compareTimeHour, compareTimeMinute);


    bool res = is_time_within_period(hourStart, minuteStart, compareTimeHour, compareTimeMinute, periodHours, periodMinutes);

    if(res) {
        printf("Time is within bounds\n");
    } else {
        printf("Time is not within bounds\n");
    }

    printf("Hello\n");

    return 0;
}


The function is_time_within_period has no dependencies and can thus be copy-pasted into any Arduino sketch.

Let the start time be 20:00 and the period 04:00. Then feeding the program different times to compare against lets us see that it indeed works.

Start: 20:00
Period: 08:00
Check time: 20:00
Time is not within bounds

Start: 20:00
Period: 08:00
Check time: 20:01
Time is within bounds

Start: 20:00
Period: 08:00
Check time: 04:00
Time is within bounds

Start: 20:00
Period: 08:00
Check time: 04:01
Time is not within bounds