Glorious Recurring Date CalendarView-Friendly Formula
<aside> ❓ What does this do?
</aside>
It simulates a recurring Task in Notion, as easy and flexible as possible and is a Calendar View-Friendly solution (you CAN Calendar By this Formula)
<aside> ❓ How do I use this formula?
</aside>
For example, if you want a Task that repeats every 3 days, pick "days" on Frequency and 3 on "Size of Frequency". A daily task would be "days" and "1". A Weekly task would be either "days" and 7 or "weeks" and 1.
The formula is adapted so that if today would be a date that fits the recursive criteria, it will display today. So, if you are repeating weekly and your starting date is a Monday and Today is also a Monday, it will show today instead of next week's Monday.
This is done on purpose because you would usually want Today's Tasks to be displayed... today. The formula would be MUCH shorter if you don't want this to happen.
<aside> ❓ Can you put the whole formula in a Formula block in case I mess it up or I encounter a glitch?
</aside>
if(empty(prop("Frequency")) and empty(prop("Size of Frequency")), prop("Dates"), if(now() < prop("Dates"), prop("Dates"), if(formatDate(dateAdd(prop("Dates"), -dateBetween(prop("Dates"), now(), prop("Frequency")) - abs(mod(dateBetween(prop("Dates"), now(), prop("Frequency")), prop("Size of Frequency"))), prop("Frequency")), "YYMMDDHH") >= formatDate(now(), "YYMMDDHH"), dateAdd(prop("Dates"), -dateBetween(prop("Dates"), now(), prop("Frequency")) - abs(mod(dateBetween(prop("Dates"), now(), prop("Frequency")), prop("Size of Frequency"))), prop("Frequency")), dateAdd(prop("Dates"), prop("Size of Frequency") - dateBetween(prop("Dates"), now(), prop("Frequency")) - abs(mod(dateBetween(prop("Dates"), now(), prop("Frequency")), prop("Size of Frequency"))), prop("Frequency")))))
<aside> ❓ How did you do this sorcery? How does this work?
</aside>
In general, the logic it's quite simple. I'm going to do the explanation using 7 days as a reference, but 7 would be equivalent to the Size of Frequency and days would be the Frequency.
We will be using the mod() function to calculate the residue of dividing the dateBetween now() and the input date, in days, divided it by 7. This is a value that is less that 7, it ranges from 0 to 7-1... and it would mean how many days is today off from the last date that was a multiple of 7 days from our start day. So, say, if our Starting date is January 1, if today is January 10, it would be 2 days, since it's 9 days away and 9/7 has 2 as a residue (January 10 is 2 days away from the last "exactly N times 7 days after" the starting date). Since we know how many days we're off from the last instance of my recurrence, we need to calculate how many days to add to the current date so that it reaches the recurrence. We can do this via a doing Size of frequency (7 days) minus the residue we just calculated:
prop("Size of Frequency")-abs(mod(dateBetween(prop("Dates"), now(), prop("Frequency")), prop("Size of Frequency")))
The value in the code above would be what we need to add to today to make it be the next date that fits the recurrence. We don't want to use now(), because we want to keep the same hours of our starting date, so we'll have to write today based on our starting date.
Since we know how many days to add to today to make it a date that fits what we want, we can use a single dateAdd function. We'll add to the starting date, the dateBetween the starting day and now(), in days, and to that, We'll add the number we need to make it fit our recurrence (every 7 days). This would be:
dateAdd(prop("Dates"), prop("Size of Frequency") - dateBetween(prop("Dates"), now(), prop("Frequency")) - abs(mod(dateBetween(prop("Dates"), now(), prop("Frequency")), prop("Size of Frequency"))), prop("Frequency"))
#Let's call this whole thing A