Skip to content

Commit

Permalink
Merge pull request #84 from danheron/fix/check-end-date
Browse files Browse the repository at this point in the history
Check that end date of calendar item is valid
  • Loading branch information
danheron authored Jan 19, 2024
2 parents ced0512 + 1d3af47 commit 84dc41e
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<MudCalendar Items="_events" Height="500"/>

@code {
public static string __description__ = "Calendar Invalid End Date Tests";

private List<CalendarItem> _events = new()
{
new CalendarItem
{
Start = DateTime.Today.AddHours(10),
End = DateTime.Today.AddHours(10),
Text = "Event 1"
}
};

}
6 changes: 6 additions & 0 deletions Heron.MudCalendar/Base/DayWeekViewBase.razor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,12 @@ private static IEnumerable<ItemPosition> CalcPositions(IEnumerable<CalendarItem>
var overlaps = new List<ItemPosition>();
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
Expand Down

0 comments on commit 84dc41e

Please sign in to comment.