I have a calendar application that uses the new PHP DateTime classes. I have a way that I handle recurring events, but it seems to be a hack, and I wanted to see if you guys have any better ideas:
- I have a recurring event that starts on 11/16/2009 (November 16, 2009)
- This will happen every 3 days.
- The event will be repeated endlessly.
Let's say a user watches a calendar for December 3100 - this event should show that it repeats every 3 days, as usual. The question is, how can I calculate those days this month?
===========================================
This is how I do it mostly, but I know that I am missing something simpler:
- I calculate the difference in days between the beginning of the month (December 1, 3100) and the start date of the event (November 16, 2009) stored as $ daysDiff
- I subtract the module, so I get a 3-day coefficient from the very beginning as follows: $ daysDiff - ($ daysDiff% 3)
- As an argument, you can say that gives me November 29, 3100 as a date.
- Then I add 3 days to this date until I have all the dates for December 31st.
My main problem is step 1. The PHP function DateInterval :: date_diff does not calculate the difference in days. It will give me years, months and days. Then I have to push the numbers to get a date estimate around December 31st. 11/16/2009 + (1090 years * 365.25 days) + (9 months * 30.5 days) + 15 days
, 9999, , , , .