Browse Source

handle start year and end year

pull/2757/head
Jason Dove 7 months ago
parent
commit
f7e023d33c
No known key found for this signature in database
  1. 2
      ErsatzTV.Core/Domain/ProgramScheduleAlternate.cs
  2. 2
      ErsatzTV.Core/Domain/Scheduling/IAlternateScheduleItem.cs
  3. 4
      ErsatzTV.Core/Domain/Scheduling/PlayoutTemplate.cs
  4. 23
      ErsatzTV.Core/Scheduling/AlternateScheduleSelector.cs

2
ErsatzTV.Core/Domain/ProgramScheduleAlternate.cs

@ -18,6 +18,8 @@ public class ProgramScheduleAlternate : IAlternateScheduleItem @@ -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;
}

2
ErsatzTV.Core/Domain/Scheduling/IAlternateScheduleItem.cs

@ -9,6 +9,8 @@ public interface IAlternateScheduleItem @@ -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; }
}

4
ErsatzTV.Core/Domain/Scheduling/PlayoutTemplate.cs

@ -21,4 +21,8 @@ public class PlayoutTemplate : IAlternateScheduleItem @@ -21,4 +21,8 @@ public class PlayoutTemplate : IAlternateScheduleItem
public DateTime DateUpdated { get; set; }
//public ICollection<DateTimeOffset> AdditionalDays { get; set; }
// placeholder data; migration will be added later
public int? StartYear => null;
public int? EndYear => null;
}

23
ErsatzTV.Core/Scheduling/AlternateScheduleSelector.cs

@ -2,7 +2,7 @@ using ErsatzTV.Core.Domain.Scheduling; @@ -2,7 +2,7 @@ using ErsatzTV.Core.Domain.Scheduling;
namespace ErsatzTV.Core.Scheduling;
public class AlternateScheduleSelector
public static class AlternateScheduleSelector
{
public static List<DayOfWeek> AllDaysOfWeek() =>
[
@ -29,33 +29,42 @@ public class AlternateScheduleSelector @@ -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,

Loading…
Cancel
Save