Member-only story
How to lock weekdays in a recurring schedule?
Pick the nearest date with the same weekday
Ever noticed how scheduling something “monthly” can be a bit unpredictable? It all comes down to the days of the week. Weeks are neat and tidy — add a week (or two), and you land on the same day you started. But months? They’re a bit more chaotic with their varying lengths.
In my last post, we tackled calculating future dates for recurring tasks. This time, we’ll dive into how to keep those tasks locked to the same day of the week. Why? Because, let’s face it, remembering tasks is way easier when they have a consistent weekly home.
Step 1 — check if we are good to go
First, we’re going to reuse some code we wrote earlier (check out my previous post for the nitty-gritty details). This code generates a list of dates based on your recurrence pattern (like, say, every month for three months).
A few words on the ForEach()
you see in the screenshot generating a list of dates. Instead of treating that list as one big blob, we want to look at each date inside it individually. To emphasize this, we give the…