Search code examples
pythontkinterscheduling

Python event scheduling


I'm working on a Python (Tkinter) app for an irrigation timer. The user enters the days of the week for each valve using the following screen: enter image description here

I'm able to process the data from the checkboxes to get the days of the week:

['Sunday', 'Tuesday', 'Friday', 'Monday', 'Thursday', 'Monday', 'Wednesday', 'Friday', 'Wednesday', 'Saturday'].

But, I need to know how many days are in between each "on" day. For example, for Valve 1, 2 days between Sunday and Tuesday and three days from Tuesday to Friday, but I don't know how to get the number days from the Friday to the next Sunday. Can anyone suggest an approach? Thanks in advance for any help!


Solution

  • def daysDifference(day1:int, day2:int):
        """
        day1: The index of the first day.
        day2: The index of the second day.
        Returns the time from one to the next.
        """
        if day1 <= day2:
            return day2 - day1
        else:
            return 7 - day1 + day2
    

    I'm pretty sure this will work.