Context
I'm making an app where I have tasks with due dates and once they are done I want to set a new due date for according to a new date according to a day of the week repeat pattern chosen by the user.
Im saving due dates as Date. Im saving the repeat pattern as Int32 (1 for Sunday, 2 for Monday, 4 for Tuesday...) but I can easily get it to an array of Strings or numbers representing each day
Problem
How do I get the next due date as Date (so I can repeat the task)?
Example
if I have a task that is completed on a Saturday and has repeat pattern of every Monday and Wednesday I want it to be set to the next Monday. If it is them completed on Monday or Tuesday I want to set the next Wednesday.
Photo of the repeat pattern choosing
Month is never selected when other days are selected. I know how to deal with the Month. The problem is just with the days of the week
I hope this snippet could be helpful
TimeInterval
can be converted inDate
using one of the Date class initializers.Never use
86400
for date math,Calendar
andIndexSet
have powerful methods to do that: