diff --git a/ErsatzTV.Application/Playouts/Queries/GetPlayoutAlternateSchedulesHandler.cs b/ErsatzTV.Application/Playouts/Queries/GetPlayoutAlternateSchedulesHandler.cs index 81505743d..63829ee1c 100644 --- a/ErsatzTV.Application/Playouts/Queries/GetPlayoutAlternateSchedulesHandler.cs +++ b/ErsatzTV.Application/Playouts/Queries/GetPlayoutAlternateSchedulesHandler.cs @@ -45,8 +45,8 @@ public class GetPlayoutAlternateSchedulesHandler(IDbContextFactory db StartMonth = 1, StartDay = 1, StartYear = null, - EndMonth = 1, - EndDay = 1, + EndMonth = 12, + EndDay = 31, EndYear = null }; diff --git a/ErsatzTV.Core.Tests/Scheduling/AlternateScheduleSelectorTests.cs b/ErsatzTV.Core.Tests/Scheduling/AlternateScheduleSelectorTests.cs index a13451a72..34af2a3f9 100644 --- a/ErsatzTV.Core.Tests/Scheduling/AlternateScheduleSelectorTests.cs +++ b/ErsatzTV.Core.Tests/Scheduling/AlternateScheduleSelectorTests.cs @@ -839,5 +839,29 @@ public static class AlternateScheduleSelectorTests result.IsNone.ShouldBeTrue(); } + + [Test] + public void LimitToDateRange_December_32nd_Should_Not_Crash() + { + var template = new PlayoutTemplate + { + DaysOfWeek = AlternateScheduleSelector.AllDaysOfWeek(), + DaysOfMonth = AlternateScheduleSelector.AllDaysOfMonth(), + MonthsOfYear = AlternateScheduleSelector.AllMonthsOfYear(), + LimitToDateRange = true, + StartMonth = 12, + StartDay = 32, + StartYear = 2022, + EndMonth = 12, + EndDay = 32, + EndYear = 2023 + }; + + Option result = AlternateScheduleSelector.GetScheduleForDate( + new List { template }, + new DateTimeOffset(2023, 3, 1, 0, 0, 0, Offset)); + + result.IsNone.ShouldBeFalse(); + } } } diff --git a/ErsatzTV.Core/Scheduling/AlternateScheduleSelector.cs b/ErsatzTV.Core/Scheduling/AlternateScheduleSelector.cs index 66a83d082..c9ca6b162 100644 --- a/ErsatzTV.Core/Scheduling/AlternateScheduleSelector.cs +++ b/ErsatzTV.Core/Scheduling/AlternateScheduleSelector.cs @@ -50,7 +50,7 @@ public static class AlternateScheduleSelector { // this should only happen with days that are greater than the actual days in the month, // so roll over to the 1st of the next month - start = new DateTime(startYear, item.StartMonth + 1, 1, 0, 0, 0, DateTimeKind.Local); + start = new DateTime(startYear, item.StartMonth, 1, 0, 0, 0, DateTimeKind.Local).AddMonths(1); } try