I need a reminder every 4th Monday (= every 28 days) from the Monday I start counting. So I thought I can have ruby script
- to send me an email ( I know how so do this part )
- every 4th Monday , not every 4th Monday of a month. ( <— how to code this bit in ruby? )
I will run the ruby scrip via cron every Monday ….
Assuming you’ve already determined that it’s a Monday, then count the days since the beginning of the year (
yday()), modulus by 28, and see if the result is in 22 and 27 (inclusive) or is 0.Given a starting (initial run) date, you can just use
step(28)to get the next date and if it equals the current date, run and then store that for your next run.As an aside, if you had meant the 4th Monday in the month, check the current day of the Month, and if it’s between the 22nd and 28th of the month, you’re in the fourth occurance of that day of the week that month.