From 1d3af4743ac1120bc80f5d4675e7865743e03b26 Mon Sep 17 00:00:00 2001 From: Dan Heron Date: Fri, 19 Jan 2024 08:56:17 +0100 Subject: [PATCH] Check that end date of calendar item is valid --- .../Calendar/CalendarInvalidEndDateTest.razor | 16 ++++++++++++++++ Heron.MudCalendar/Base/DayWeekViewBase.razor.cs | 6 ++++++ 2 files changed, 22 insertions(+) create mode 100644 Heron.MudCalendar.UnitTests.Viewer/TestComponents/Calendar/CalendarInvalidEndDateTest.razor diff --git a/Heron.MudCalendar.UnitTests.Viewer/TestComponents/Calendar/CalendarInvalidEndDateTest.razor b/Heron.MudCalendar.UnitTests.Viewer/TestComponents/Calendar/CalendarInvalidEndDateTest.razor new file mode 100644 index 0000000..416ef8f --- /dev/null +++ b/Heron.MudCalendar.UnitTests.Viewer/TestComponents/Calendar/CalendarInvalidEndDateTest.razor @@ -0,0 +1,16 @@ + + +@code { + public static string __description__ = "Calendar Invalid End Date Tests"; + + private List _events = new() + { + new CalendarItem + { + Start = DateTime.Today.AddHours(10), + End = DateTime.Today.AddHours(10), + Text = "Event 1" + } + }; + +} diff --git a/Heron.MudCalendar/Base/DayWeekViewBase.razor.cs b/Heron.MudCalendar/Base/DayWeekViewBase.razor.cs index e0e0238..1a8b2ac 100644 --- a/Heron.MudCalendar/Base/DayWeekViewBase.razor.cs +++ b/Heron.MudCalendar/Base/DayWeekViewBase.razor.cs @@ -233,6 +233,12 @@ private static IEnumerable CalcPositions(IEnumerable var overlaps = new List(); foreach (var item in items) { + // Check that the end date is valid + if (item.End.HasValue && item.End <= item.Start) + { + throw new ApplicationException("End date of calendar item must be after start date"); + } + overlaps.RemoveAll(o => (o.Item.End ?? o.Item.Start.AddHours(1)) <= item.Start); // Create new position object