We need to use our appointment data beyond having it displayed in the Calendar. We need to generate reports and lists based on dates and we are having trouble knowing when appointments occur because we aren't sure how to calculate the date based on the recurrence string.
Is there a .Net C# SDK that can calculate dates based on the appointment start and end date, recurrence string, and exception dates?
For example:
Appointment Start Date: 2021-11-01T14:00:00.000Z
Appointment End Date: 2021-11-01T14:00:00.000Z
Recurrence String: FREQ=MONTHLY;BYDAY=MO;BYSETPOS=1
Exception Dates: [2021-12-06T14:00:00.000Z]
I'm looking for server side code or an API. I can't send all of our appointments to the front end to calculate it first, we need to use the backend server code to minimize the amount of data we send before hand.
Animal, thank you for your responses but there is a misunderstanding here.
We Are NOT loading the appointments into the UI in this use case.
We are using the appointment data to generate reports alongside other data.
Therefore we need to be able to calculate the appointments dates without using the UI.
I was able to find what I need. I'm posting a solution to help others to calculate dates without using the UI.
The recurrence rule is a standard format: iCalendar (RFC 5545)
In .Net there is a library you can use called Ical.Net which you can get through a Nuget Package.
Example Code
var appointmentR = GenericRepository.Table<Appointment>().Where(a => a.Id == "61b0fb7babb53d4d16355a10").First();
var vEvent = new Ical.Net.CalendarComponents.CalendarEvent
{
DtEnd = new Ical.Net.DataTypes.CalDateTime(appointmentR.AppointmentEndDateTime),
DtStart = new Ical.Net.DataTypes.CalDateTime(appointmentR.AppointmentDateTime),
};
vEvent.RecurrenceRules.Add(new Ical.Net.DataTypes.RecurrencePattern("FREQ=DAILY;UNTIL=20211217T075900"));
var vCalendar = new Ical.Net.Calendar();
vCalendar.Events.Add(vEvent);
var occurances = vCalendar.GetOccurrences(DateTime.Now, DateTime.Now.AddYears(1));