Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What's a good data structure for periodic or recurring dates?

Is there a published data structure for storing periodic or recurring dates? Something that can handle:

  1. The pump need recycling every five days.
  2. Payday is every second Friday.
  3. Thanksgiving Day is the second Monday in October (US: the fourth Thursday in November).
  4. Valentine's Day is every February 14th.
  5. Solstice is (usually) every June 21st and December 21st.
  6. Easter is the Sunday after the first full moon on or after the day of the vernal equinox (okay, this one's a bit of a stretch).

I reckon cron's internal data structure can handle #1, #4, #5 (two rules), and maybe #2, but I haven't had a look at it. MS Outlook and other calendars seem to be able to handle the first five, but I don't have that source code lying around.

like image 864
yukondude Avatar asked Jun 17 '09 22:06

yukondude


1 Answers

Use a iCalendar implementation library, like these ones: ruby, java, php, python, .net and java, and then add support for calculating special dates.

like image 55
mgcm Avatar answered Nov 04 '22 08:11

mgcm