lundi 15 avril 2019

How to skip dates in Python using checkboxes

I have 4 checkboxes each representing a date such as:

Week 1: 01/01/2019  [  ] - checkbox 1
Week 2: 08/01/2019  [  ] - checkbox 2
Week 3: 15/01/2019  [  ] - checkbox 3
Week 4: 22/01/2019  [  ] - checkbox 4
Week To Pay 29/01/2019

I need to work out a logical way that skips the dates forwards a week if checked and reverts back to normal if unchecked. I wondered if there is an elegant way of handling different combinations of checked and unchecked buttons so the dates are always right..eg. if 1 and 3 are checked these dates are skipped.

I have tried defs for each individual checkbox and also an alternative of one submit button to rule them all but the logic seems to escape me.

W1 = W1 = timedelta(days=7)
week_one_raw = "01/01/2019"
week_one_raw = datetime.strptime(FIXED_WEEK_1, '%d/%m/%Y')

#the variables that need to be right are as follows and are set as their default

week_one_refined = week_one_raw
week_two_refined = week_one_raw + W1
week_three_refined = week_two_refined + W1
week_four_refined = week_three_refined + W1
week_to_pay_refined = week_four_refined + W1


So far using for loops for checking whether the check box value is 0 or 1 I have managed to make it work absolutely fine. The error comes when different combinations of check boxes are on and off rather than just 1. I'm looking for an elegant logical solution rather than programming every single possible combination separately.




Aucun commentaire:

Enregistrer un commentaire