I’m writing an application which needs to support dates and date ranges for events. I’d particularly like to have robust support for regularly recurring events such as store opening hours or regular trips.
I’d like to be able to support the user entering a query such as:
“We’re open 8am-6pm every Weekday, and 8am-10am on Saturdays”
“I’m available every Friday between 6pm-10pm, except the third friday of each month”
“Recurring meeting on the 25th of every month”
“Recurring meeting every 28 days starting from the 3rd November”
And then, being quickly able to tell whether a given DateTime falls within the specified bounds, or where the overlaps between two user specified times are.
Is there a library out there which could fulfill my needs?
edit: To clarify, I don’t particularly need natural language parsing, just the complicated intervals and overlaps.
You should take a look at Joda-Time http://joda-time.sourceforge.net/. It’s pretty much the best Java date-time library and I think you could use intervals for specifying when a store is open:
An interval in Joda-Time represents an interval of time from one instant to another instant.
You should also take a look at http://code.google.com/p/google-rfc-2445/ as it seems closer to the recurring events you want to use. Also I think this library actually uses Joda Time.