Handle unrepresentable datetimes
This commit is contained in:
parent
2c514c62f1
commit
2fbd45d643
@ -449,6 +449,19 @@ namespace MatFileHandler.Tests
|
||||
Assert.That(duration[2], Is.EqualTo(new TimeSpan(1, 3, 5)));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Test unrepresentable datetime.
|
||||
/// </summary>
|
||||
[Test]
|
||||
public void TestDatetime_Unrepresentable()
|
||||
{
|
||||
var matFile = GetTests("good")["datetime-unrepresentable"];
|
||||
var obj = matFile["d"].Value as IMatObject;
|
||||
var datetime = new DatetimeAdapter(obj);
|
||||
var d0 = datetime[0];
|
||||
Assert.That(d0, Is.Null);
|
||||
}
|
||||
|
||||
private static AbstractTestDataFactory<IMatFile> GetTests(string factoryName) =>
|
||||
new MatTestDataFactory(Path.Combine(TestDirectory, factoryName));
|
||||
|
||||
|
BIN
MatFileHandler.Tests/test-data/good/datetime-unrepresentable.mat
Normal file
BIN
MatFileHandler.Tests/test-data/good/datetime-unrepresentable.mat
Normal file
Binary file not shown.
@ -57,6 +57,17 @@ namespace MatFileHandler
|
||||
/// </summary>
|
||||
/// <param name="list">Indices.</param>
|
||||
/// <returns>Value converted to <see cref="DateTimeOffset"/>.</returns>
|
||||
public DateTimeOffset this[params int[] list] => epoch.AddMilliseconds(data[Dimensions.DimFlatten(list)]);
|
||||
public DateTimeOffset? this[params int[] list]
|
||||
{
|
||||
get
|
||||
{
|
||||
var milliseconds = data[Dimensions.DimFlatten(list)];
|
||||
if (milliseconds < -62_135_596_800_000.0 || milliseconds > 253_402_300_799_999.0)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return epoch.AddMilliseconds(milliseconds);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user