diff --git a/ErsatzTV.Core/Domain/ProgramScheduleAlternate.cs b/ErsatzTV.Core/Domain/ProgramScheduleAlternate.cs index f18b2cecb..6a813ee7c 100644 --- a/ErsatzTV.Core/Domain/ProgramScheduleAlternate.cs +++ b/ErsatzTV.Core/Domain/ProgramScheduleAlternate.cs @@ -18,6 +18,8 @@ public class ProgramScheduleAlternate : IAlternateScheduleItem public bool LimitToDateRange => false; public int StartMonth => 0; public int StartDay => 0; + public int? StartYear => null; public int EndMonth => 0; public int EndDay => 0; + public int? EndYear => null; } diff --git a/ErsatzTV.Core/Domain/Scheduling/IAlternateScheduleItem.cs b/ErsatzTV.Core/Domain/Scheduling/IAlternateScheduleItem.cs index 96641268b..c44ef77bd 100644 --- a/ErsatzTV.Core/Domain/Scheduling/IAlternateScheduleItem.cs +++ b/ErsatzTV.Core/Domain/Scheduling/IAlternateScheduleItem.cs @@ -9,6 +9,8 @@ public interface IAlternateScheduleItem bool LimitToDateRange { get; } int StartMonth { get; } int StartDay { get; } + int? StartYear { get; } int EndMonth { get; } int EndDay { get; } + int? EndYear { get; } } diff --git a/ErsatzTV.Core/Domain/Scheduling/PlayoutTemplate.cs b/ErsatzTV.Core/Domain/Scheduling/PlayoutTemplate.cs index dfa467bb0..d9775a235 100644 --- a/ErsatzTV.Core/Domain/Scheduling/PlayoutTemplate.cs +++ b/ErsatzTV.Core/Domain/Scheduling/PlayoutTemplate.cs @@ -21,4 +21,8 @@ public class PlayoutTemplate : IAlternateScheduleItem public DateTime DateUpdated { get; set; } //public ICollection AdditionalDays { get; set; } + + // placeholder data; migration will be added later + public int? StartYear => null; + public int? EndYear => null; } diff --git a/ErsatzTV.Core/Scheduling/AlternateScheduleSelector.cs b/ErsatzTV.Core/Scheduling/AlternateScheduleSelector.cs index de07aece9..66a83d082 100644 --- a/ErsatzTV.Core/Scheduling/AlternateScheduleSelector.cs +++ b/ErsatzTV.Core/Scheduling/AlternateScheduleSelector.cs @@ -2,7 +2,7 @@ using ErsatzTV.Core.Domain.Scheduling; namespace ErsatzTV.Core.Scheduling; -public class AlternateScheduleSelector +public static class AlternateScheduleSelector { public static List AllDaysOfWeek() => [ @@ -29,33 +29,42 @@ public class AlternateScheduleSelector bool reverse = item.StartMonth * 100 + item.StartDay > item.EndMonth * 100 + item.EndDay; - int year = date.LocalDateTime.Year; + int startYear = date.LocalDateTime.Year; + int endYear = date.LocalDateTime.Year; + + if (item.StartYear.HasValue && item.EndYear.HasValue) + { + startYear = item.StartYear.Value; + endYear = item.EndYear.Value; + reverse = false; + } + DateTime start; DateTime end; try { - start = new DateTime(year, item.StartMonth, item.StartDay, 0, 0, 0, DateTimeKind.Local); + start = new DateTime(startYear, item.StartMonth, item.StartDay, 0, 0, 0, DateTimeKind.Local); } catch (ArgumentOutOfRangeException) { // 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(year, item.StartMonth + 1, 1, 0, 0, 0, DateTimeKind.Local); + start = new DateTime(startYear, item.StartMonth + 1, 1, 0, 0, 0, DateTimeKind.Local); } try { - end = new DateTime(year, item.EndMonth, item.EndDay, 0, 0, 0, DateTimeKind.Local); + end = new DateTime(endYear, item.EndMonth, item.EndDay, 0, 0, 0, DateTimeKind.Local); } catch (ArgumentOutOfRangeException) { // this should only happen with days that are greater than the actual days in the month, // so reduce to the max days in the month end = new DateTime( - year, + endYear, item.EndMonth, - DateTime.DaysInMonth(year, item.EndMonth), + DateTime.DaysInMonth(endYear, item.EndMonth), 0, 0, 0,