diff --git a/ErsatzTV.Core.Tests/Scheduling/BlockScheduling/EffectiveBlockTests.cs b/ErsatzTV.Core.Tests/Scheduling/BlockScheduling/EffectiveBlockTests.cs index 59e872d8a..366775a77 100644 --- a/ErsatzTV.Core.Tests/Scheduling/BlockScheduling/EffectiveBlockTests.cs +++ b/ErsatzTV.Core.Tests/Scheduling/BlockScheduling/EffectiveBlockTests.cs @@ -7,8 +7,8 @@ namespace ErsatzTV.Core.Tests.Scheduling.BlockScheduling; public static class EffectiveBlockTests { - private static DateTimeOffset GetLocalDate(int year, int month, int day) => - new(year, month, day, 0, 0, 0, TimeSpan.FromHours(-6)); + private static DateTimeOffset GetLocalDate(int year, int month, int day, TimeZoneInfo tz) => + new(year, month, day, 0, 0, 0, tz.GetUtcOffset(new DateTime(year, month, day))); private static Template SingleBlockTemplate(DateTimeOffset dateUpdated) { @@ -60,9 +60,10 @@ public static class EffectiveBlockTests } ]; - DateTimeOffset start = GetLocalDate(2024, 1, 15).AddHours(9); + TimeZoneInfo tz = TimeZoneInfo.Local; + DateTimeOffset start = GetLocalDate(2024, 1, 15, tz).AddHours(9); - List result = EffectiveBlock.GetEffectiveBlocks(templates, start, 5); + List result = EffectiveBlock.GetEffectiveBlocks(templates, start, tz, 5); result.Count.ShouldBe(0); } @@ -85,20 +86,21 @@ public static class EffectiveBlockTests } ]; - DateTimeOffset start = GetLocalDate(2024, 1, 15).AddHours(9); + TimeZoneInfo tz = TimeZoneInfo.Local; + DateTimeOffset start = GetLocalDate(2024, 1, 15, tz).AddHours(9); - List result = EffectiveBlock.GetEffectiveBlocks(templates, start, 5); + List result = EffectiveBlock.GetEffectiveBlocks(templates, start, tz, 5); result.Count.ShouldBe(3); result[0].Start.DayOfWeek.ShouldBe(DayOfWeek.Monday); - result[0].Start.Date.ShouldBe(GetLocalDate(2024, 1, 15).Date); + result[0].Start.Date.ShouldBe(GetLocalDate(2024, 1, 15, tz).Date); result[1].Start.DayOfWeek.ShouldBe(DayOfWeek.Wednesday); - result[1].Start.Date.ShouldBe(GetLocalDate(2024, 1, 17).Date); + result[1].Start.Date.ShouldBe(GetLocalDate(2024, 1, 17, tz).Date); result[2].Start.DayOfWeek.ShouldBe(DayOfWeek.Friday); - result[2].Start.Date.ShouldBe(GetLocalDate(2024, 1, 19).Date); + result[2].Start.Date.ShouldBe(GetLocalDate(2024, 1, 19, tz).Date); } [Test] @@ -125,7 +127,7 @@ public static class EffectiveBlockTests var start = new DateTime(2024, 3, 9, 0, 0, 0, DateTimeKind.Unspecified); var dto = new DateTimeOffset(start, tz.GetUtcOffset(start)); - List result = EffectiveBlock.GetEffectiveBlocks(templates, dto, 5); + List result = EffectiveBlock.GetEffectiveBlocks(templates, dto, tz, 5); result.Count.ShouldBe(5); @@ -164,7 +166,7 @@ public static class EffectiveBlockTests var start = new DateTime(2024, 11, 2, 0, 0, 0, DateTimeKind.Unspecified); var dto = new DateTimeOffset(start, tz.GetUtcOffset(start)); - List result = EffectiveBlock.GetEffectiveBlocks(templates, dto, 5); + List result = EffectiveBlock.GetEffectiveBlocks(templates, dto, tz, 5); result.Count.ShouldBe(5); diff --git a/ErsatzTV.Core/Scheduling/BlockScheduling/BlockPlayoutBuilder.cs b/ErsatzTV.Core/Scheduling/BlockScheduling/BlockPlayoutBuilder.cs index 2076ed696..e0af3d321 100644 --- a/ErsatzTV.Core/Scheduling/BlockScheduling/BlockPlayoutBuilder.cs +++ b/ErsatzTV.Core/Scheduling/BlockScheduling/BlockPlayoutBuilder.cs @@ -55,7 +55,7 @@ public class BlockPlayoutBuilder( // get blocks to schedule List blocksToSchedule = - EffectiveBlock.GetEffectiveBlocks(referenceData.PlayoutTemplates, start, daysToBuild); + EffectiveBlock.GetEffectiveBlocks(referenceData.PlayoutTemplates, start, TimeZoneInfo.Local, daysToBuild); if (blocksToSchedule.Count == 0) { diff --git a/ErsatzTV.Core/Scheduling/BlockScheduling/EffectiveBlock.cs b/ErsatzTV.Core/Scheduling/BlockScheduling/EffectiveBlock.cs index 9a4d3b29f..855652c81 100644 --- a/ErsatzTV.Core/Scheduling/BlockScheduling/EffectiveBlock.cs +++ b/ErsatzTV.Core/Scheduling/BlockScheduling/EffectiveBlock.cs @@ -7,10 +7,9 @@ internal record EffectiveBlock(Block Block, BlockKey BlockKey, DateTimeOffset St public static List GetEffectiveBlocks( ICollection templates, DateTimeOffset start, + TimeZoneInfo timeZone, int daysToBuild) { - var timeZone = TimeZoneInfo.Local; - DateTimeOffset finish = start.AddDays(daysToBuild); var effectiveBlocks = new List();