Skip to content

Commit

Permalink
imp - Added more calendar validation steps
Browse files Browse the repository at this point in the history
---

To validate the calendar more deeply, we've created validation steps that conform to the vCalendar 2.0 specifications.

---

Type: imp
Breaking: False
Doc Required: False
Backport Required: False
Part: 1/1
  • Loading branch information
AptiviCEO committed Oct 3, 2024
1 parent 3434aa6 commit cb785b8
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions VisualCard.Calendar/Parsers/VCalendarParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@
using VisualCard.Parts.Enums;
using VisualCard.Parsers;
using VisualCard.Parsers.Arguments;
using VisualCard.Calendar.Parts.Implementations.Event;
using VisualCard.Calendar.Parts.Implementations.Todo;

namespace VisualCard.Calendar.Parsers
{
Expand Down Expand Up @@ -300,6 +302,12 @@ internal void ValidateCalendar(Parts.Calendar calendar)
if (priority.Value < 0 || priority.Value > 9)
throw new ArgumentOutOfRangeException(nameof(CalendarIntegersEnum.PercentComplete), priority.Value, "Percent completion may not be less than zero or greater than 100");
}

// Check for conflicts
var dtends = eventInfo.GetPartsArray<DateEndInfo>();
var durations = eventInfo.GetString(CalendarStringsEnum.Duration);
if (dtends.Length > 0 && durations.Length > 0)
throw new InvalidDataException("Date end and duration conflict found.");
}
foreach (var todoInfo in calendar.Todos)
{
Expand All @@ -323,6 +331,15 @@ internal void ValidateCalendar(Parts.Calendar calendar)
if (priority.Value < 0 || priority.Value > 9)
throw new ArgumentOutOfRangeException(nameof(CalendarIntegersEnum.PercentComplete), priority.Value, "Percent completion may not be less than zero or greater than 100");
}

// Check for conflicts
var dtstarts = todoInfo.GetPartsArray<DateStartInfo>();
var dues = todoInfo.GetPartsArray<DueDateInfo>();
var durations = todoInfo.GetString(CalendarStringsEnum.Duration);
if (dues.Length > 0 && durations.Length > 0)
throw new InvalidDataException("Due date and duration conflict found.");
if (durations.Length > 0 && dtstarts.Length == 0)
throw new InvalidDataException("There is no date start to add to the duration.");
}

// Continue if we have a calendar with version 2.0
Expand All @@ -347,6 +364,12 @@ internal void ValidateCalendar(Parts.Calendar calendar)
{
if (!ValidateComponent(ref expectedTimeZoneFields, out string[] actualTimeZoneFields, timezoneInfo))
throw new InvalidDataException($"The following keys [{string.Join(", ", expectedTimeZoneFields)}] are required in the timezone representation. Got [{string.Join(", ", actualTimeZoneFields)}].");

// Check for standard and/or daylight
if (timezoneInfo.StandardTimeList.Length == 0 && timezoneInfo.DaylightTimeList.Length == 0)
throw new InvalidDataException("One of the standard/daylight components is required.");

// Verify the standard and/or daylight components
foreach (var standardInfo in timezoneInfo.StandardTimeList)
{
if (!ValidateComponent(ref expectedStandardFields, out string[] actualStandardFields, standardInfo))
Expand Down

0 comments on commit cb785b8

Please sign in to comment.