Almost all of that function looks the same, except it's there twice. The only difference is in one spot you have >, and in another <.
How about...
How about...
# if stophr is BEFORE the starthr, swap all values, so starthr is always the smaller value if stophr < starthr: starthr, startmin, stophr, stopmin = stophr, stopmin, starthr, startmin if datetime.time(starthr, startmin) <= now_time <= datetime.time(stophr, stopmin): return True return False #...that's it. you've saved yourself 3 lines, and it's easier to make changes/understand