Our powerful JS Calendar component


Post by dwilliams »

Hello,

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]

Regards,

Dan


Post by Animal »

There is a private method in the EventStore which you can use to access occurrences: https://127.0.0.1/old_bryntum/bryntum-suite/Calendar/docs/#Scheduler/data/EventStore#function-getOccurrencesForTimeSpan

It's a stable API, so should be safe enough. So you could do

myEventStore.getOccurrencesForTimeSpan(myEvent, new Date(2021, 11, 1), new Date(2022, 11, 1))

To find the occurences of myEvent which intersect that date range.


Post by dwilliams »

Hey Animal,

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.

Dan


Post by Animal »

You don't need to send them.

The EventStore calculates all occurrences which apply inside the range that the UI asks for.

You just must send the base events which are still in force, and send them, however long ago they started. The EventStore does the rest.


Post by Animal »

See this feature: https://bryntum.com/docs/calendar/api/Calendar/feature/LoadOnDemand

These guidelines probably need to be hoisted to a higher level explainer at the data API level which is shared between all products.

I'll try to get this principle highlighted.


Post by Animal »

I have added this to the header info for the EventStore class in my current working branch.

It's a difficult concept to get across, does this help explain what's needed?

Screenshot 2021-12-09 at 09.58.51.png
Screenshot 2021-12-09 at 09.58.51.png (85.71 KiB) Viewed 904 times

Post by dwilliams »

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.

Is there a way to do this?

Regards,

Dan


Post by dwilliams »

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));

Post by Maxim Gorkovsky »

Thank you for sharing your solution!


Post Reply