Dec-13-2016, 10:53 PM
(This post was last modified: Dec-13-2016, 10:54 PM by PickyBiker.)
Okay, after the last comment, I combined the if statements and I also turned this into a function so here's what it looks like now. I have not yet tested it fully, but it looks right.
def onrange(self, starthr, startmin, stophr, stopmin): tm= datetime.datetime.now() now_time = tm.time() #now_time = datetime.time(hour=0, minute=2) if stophr >= starthr: if datetime.time(starthr, startmin) <= now_time <= datetime.time(stophr, stopmin): # return True print("yes") else: # return False print("no") else: if datetime.time(starthr, startmin) >= now_time >= datetime.time(stophr, stopmin): # return True print("yes") else: # return False print("no")