diff --git a/TeslaMateAgile.Tests/Services/FixedPriceWeeklyServiceTests.cs b/TeslaMateAgile.Tests/Services/FixedPriceWeeklyServiceTests.cs index bd8488a..f64a23b 100644 --- a/TeslaMateAgile.Tests/Services/FixedPriceWeeklyServiceTests.cs +++ b/TeslaMateAgile.Tests/Services/FixedPriceWeeklyServiceTests.cs @@ -180,6 +180,7 @@ private FixedPriceWeeklyService Setup(string timeZone, List prices) new List { // Monday + new() { ValidFrom = new DateTimeOffset(new DateTime(2023, 1, 1, 5, 0, 0, DateTimeKind.Utc)), ValidTo = new DateTimeOffset(new DateTime(2023, 1, 2, 5, 0, 0, DateTimeKind.Utc)), Value = 0.042m }, new() { ValidFrom = new DateTimeOffset(new DateTime(2023, 1, 2, 5, 0, 0, DateTimeKind.Utc)), ValidTo = new DateTimeOffset(new DateTime(2023, 1, 2, 8, 30, 0, DateTimeKind.Utc)), Value = 0.04m }, new() { ValidFrom = new DateTimeOffset(new DateTime(2023, 1, 2, 8, 30, 0, DateTimeKind.Utc)), ValidTo = new DateTimeOffset(new DateTime(2023, 1, 2, 11, 0, 0, DateTimeKind.Utc)), Value = 0.035m }, new() { ValidFrom = new DateTimeOffset(new DateTime(2023, 1, 2, 11, 0, 0, DateTimeKind.Utc)), ValidTo = new DateTimeOffset(new DateTime(2023, 1, 2, 13, 0, 0, DateTimeKind.Utc)), Value = 0.02m }, @@ -256,7 +257,27 @@ private FixedPriceWeeklyService Setup(string timeZone, List prices) new DateTimeOffset(new DateTime(2024, 11, 5, 20, 50, 33, DateTimeKind.Utc)), new List { - new() { ValidFrom = new DateTimeOffset(new DateTime(2024, 11, 5, 17, 00, 00, DateTimeKind.Utc)), ValidTo = new DateTimeOffset(new DateTime(2024, 11, 5, 22, 0, 0, DateTimeKind.Utc)), Value = 0.052004m }, + new() { ValidFrom = new DateTimeOffset(new DateTime(2024, 11, 5, 17, 0, 0, DateTimeKind.Utc)), ValidTo = new DateTimeOffset(new DateTime(2024, 11, 5, 22, 0, 0, DateTimeKind.Utc)), Value = 0.052004m }, + } + }, + new object[] + { + "TimeZonePreviousDay", + "America/Denver", + new List + { + "Mon-Fri=00:00-08:00=0.052004", + "Mon-Fri=08:00-10:00=0.253532", + "Mon-Fri=10:00-15:00=0.052004", + "Mon-Fri=15:00-20:00=0.253532", + "Mon-Fri=20:00-00:00=0.052004", + "Sat-Sun=0.052004" + }, + new DateTimeOffset(new DateTime(2024, 11, 4, 1, 22, 55, DateTimeKind.Utc)), + new DateTimeOffset(new DateTime(2024, 11, 4, 1, 40, 58, DateTimeKind.Utc)), + new List + { + new() { ValidFrom = new DateTimeOffset(new DateTime(2024, 11, 3, 6, 0, 0, DateTimeKind.Utc)), ValidTo = new DateTimeOffset(new DateTime(2024, 11, 4, 7, 0, 0, DateTimeKind.Utc)), Value = 0.052004m }, } } }; diff --git a/TeslaMateAgile/Services/FixedPriceWeeklyService.cs b/TeslaMateAgile/Services/FixedPriceWeeklyService.cs index bfdf559..0100f0d 100644 --- a/TeslaMateAgile/Services/FixedPriceWeeklyService.cs +++ b/TeslaMateAgile/Services/FixedPriceWeeklyService.cs @@ -28,10 +28,10 @@ public Task> GetPriceData(DateTimeOffset from, DateTimeOffset // Get all days between the range inclusive - var fromDate = from.Date; - var toDate = to.Date; + var fromDate = from.Add(_timeZone.GetUtcOffset(from)).Date; + var toDate = to.Add(_timeZone.GetUtcOffset(to)).Date; var days = new Dictionary>(); - for (var date = from.Date; date <= to.Date; date = date.AddDays(1)) + for (var date = fromDate; date <= toDate; date = date.AddDays(1)) { prices.AddRange(GetPriceDataForDate(date)); } @@ -40,6 +40,7 @@ public Task> GetPriceData(DateTimeOffset from, DateTimeOffset prices = prices.Where(x => x.ValidFrom < to && x.ValidTo > from).ToList(); + return Task.FromResult((IEnumerable)prices); }