We have a java backend application which stores events in a mysql database. The frontend…
- User
We have a java backend application which stores events in a mysql database. The frontend can get a list of events via a REST API. Now we want to implement recurring events. e.g. daily or weekly events. What is the best way to do it. Can you recommend a data schema and maybe some standards or libraries?
- Assistant
Implementing recurring events can be a bit challenging, but there are different approaches you can take. Here are some recommendations for data schema, standards, and libraries:
- Data Schema: To support recurring events, you need to store more than just the date and time of the event. Here is a data schema that could work for you:
- id (unique identifier)
- title (text)
- description (text)
- start_date (datetime)
- end_date (datetime)
- User
scheduling is not part of our use case. We just have to be able to return in the API response all the recurrence instances for a given time frame.
- Assistant
In that case, you can generate all the recurrence instances for a given time frame on the server-side and return them in the API response. Here's an approach you can take:
- Define the data schema for recurring events as I mentioned in my previous answer.
- When a user requests a list of events for a particular time frame, retrieve all the recurring events that start within that time frame.
- For each recurring event, generate all the recurrence instances that fall within the requested time frame based on the recurrence type, interval, and days.
- Merge the recurring instances with the non-recurring events and return the combined list of events to the user.
Here's some sample code to generate all the recurrence instances for a daily event:
- User
can you show me the code if we use the ICAL format for storing the recurrence rule.
And also show me the code if we want to use the "lib-recur" library
- Assistant
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.