using System.Collections.Generic;
using System.Globalization;
using System.Text.RegularExpressions;
using Ical.Net.CalendarComponents;
using Ical.Net.DataTypes;
using Ical.Net.Evaluation;
using Ical.Net.Serialization;
using Ical.Net.Serialization.DataTypes;
public static void Main()
Guid id = Guid.NewGuid();
string timeZoneId = TimeZoneInfo.Local.Id;
DateTime start = new DateTime(2024, 10, 19, 18, 0, 0, DateTimeKind.Local);
DateTime end = new DateTime(2024, 10, 19, 19, 0, 0, DateTimeKind.Local);
DateTime exceptionDate = new DateTime(2024, 10, 19, 21, 0, 0, DateTimeKind.Local);
RecurrencePattern recurrencePattern = new RecurrencePattern(FrequencyType.Hourly);
recurrencePattern.Count = 2;
recurrencePattern.Interval = 3;
IDateTime exceptionOccurrsOn = new CalDateTime(exceptionDate, timeZoneId);
PeriodList exceptionDates = new PeriodList();
exceptionDates.Add(exceptionOccurrsOn);
exceptionDates.Add(exceptionOccurrsOn.AddDays(1));
CalendarEvent myRecurringEvent = new CalendarEvent();
myRecurringEvent.Summary = "My Recurring Event";
myRecurringEvent.Uid = id.ToString();
myRecurringEvent.Start = new CalDateTime(start, timeZoneId);
myRecurringEvent.End = new CalDateTime(end, timeZoneId);
myRecurringEvent.RecurrenceRules.Add(recurrencePattern);
myRecurringEvent.ExceptionDates.Add(exceptionDates);
Ical.Net.Calendar calendar = new Ical.Net.Calendar();
calendar.Events.Add(myRecurringEvent);
CalendarSerializer serializer = new CalendarSerializer();
string schedulerData = serializer.SerializeToString(calendar);
Console.WriteLine(schedulerData);
Ical.Net.Calendar deserializedCalendar = Ical.Net.Calendar.Load(schedulerData);
DateTime date = new DateTime(2024, 10, 19);
HashSet<Occurrence> occurrences = deserializedCalendar.GetOccurrences<CalendarEvent>(date);
Console.WriteLine(occurrences.Count());