fix: handle Local and Unspecified DateTimeKind in CompactNordPoolDayPrice conversion
Made-with: Cursor
This commit is contained in:
@@ -48,6 +48,33 @@ public class CompactNordPoolDayPriceTests
|
||||
result.End.Should().Be(0L);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void FromDayPrice_WhenDateTimeKindIsLocal_ShouldConvertToUtcWithoutThrowing()
|
||||
{
|
||||
var localStart = new DateTime(2026, 3, 19, 12, 0, 0, DateTimeKind.Local);
|
||||
var localEnd = new DateTime(2026, 3, 19, 12, 15, 0, DateTimeKind.Local);
|
||||
var dayPrice = new NordPoolDayPrice { Start = localStart, End = localEnd, Price = 10.0 };
|
||||
|
||||
var act = () => CompactNordPoolDayPrice.FromDayPrice(dayPrice);
|
||||
|
||||
act.Should().NotThrow();
|
||||
var result = act();
|
||||
var expectedStart = new DateTimeOffset(localStart.ToUniversalTime(), TimeSpan.Zero).ToUnixTimeSeconds();
|
||||
result.Start.Should().Be(expectedStart);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void FromDayPrice_WhenDateTimeKindIsUnspecified_ShouldConvertWithoutThrowing()
|
||||
{
|
||||
var unspecifiedStart = new DateTime(2026, 3, 19, 12, 0, 0, DateTimeKind.Unspecified);
|
||||
var unspecifiedEnd = new DateTime(2026, 3, 19, 12, 15, 0, DateTimeKind.Unspecified);
|
||||
var dayPrice = new NordPoolDayPrice { Start = unspecifiedStart, End = unspecifiedEnd, Price = 10.0 };
|
||||
|
||||
var act = () => CompactNordPoolDayPrice.FromDayPrice(dayPrice);
|
||||
|
||||
act.Should().NotThrow();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void FromDayPrice_WhenPriceIsNull_ShouldPreserveNull()
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user