diff --git a/MatFileHandler.Tests/MatFileReaderTests.cs b/MatFileHandler.Tests/MatFileReaderTests.cs index b317cf3..fd35342 100755 --- a/MatFileHandler.Tests/MatFileReaderTests.cs +++ b/MatFileHandler.Tests/MatFileReaderTests.cs @@ -449,6 +449,19 @@ namespace MatFileHandler.Tests Assert.That(duration[2], Is.EqualTo(new TimeSpan(1, 3, 5))); } + /// + /// Test unrepresentable datetime. + /// + [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 GetTests(string factoryName) => new MatTestDataFactory(Path.Combine(TestDirectory, factoryName)); diff --git a/MatFileHandler.Tests/test-data/good/datetime-unrepresentable.mat b/MatFileHandler.Tests/test-data/good/datetime-unrepresentable.mat new file mode 100644 index 0000000..9988076 Binary files /dev/null and b/MatFileHandler.Tests/test-data/good/datetime-unrepresentable.mat differ diff --git a/MatFileHandler.sln b/MatFileHandler.sln index 0c4a142..ad160eb 100755 --- a/MatFileHandler.sln +++ b/MatFileHandler.sln @@ -1,7 +1,7 @@  Microsoft Visual Studio Solution File, Format Version 12.00 -# Visual Studio 15 -VisualStudioVersion = 15.0.28107.0 +# Visual Studio Version 16 +VisualStudioVersion = 16.0.28621.142 MinimumVisualStudioVersion = 10.0.40219.1 Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MatFileHandler", "MatFileHandler\MatFileHandler.csproj", "{C0CD11D3-016A-4FCD-AF0B-D745F79F3749}" EndProject @@ -9,6 +9,7 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MatFileHandler.Tests", "Mat EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{2CF58D3D-4CEC-419B-AD67-58665A888BDF}" ProjectSection(SolutionItems) = preProject + LICENSE.md = LICENSE.md MatFileHandler\Objects.md = MatFileHandler\Objects.md README.md = README.md EndProjectSection diff --git a/MatFileHandler/DatetimeAdapter.cs b/MatFileHandler/DatetimeAdapter.cs index c86371f..bdac59f 100644 --- a/MatFileHandler/DatetimeAdapter.cs +++ b/MatFileHandler/DatetimeAdapter.cs @@ -56,7 +56,18 @@ namespace MatFileHandler /// Gets values of datetime object at given position in the array converted to . /// /// Indices. - /// Value converted to . - public DateTimeOffset this[params int[] list] => epoch.AddMilliseconds(data[Dimensions.DimFlatten(list)]); + /// Value converted to ; null if the resulting value is unrepresentable. + 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); + } + } } } \ No newline at end of file diff --git a/MatFileHandler/MatFileHandler.csproj b/MatFileHandler/MatFileHandler.csproj index 7152830..6e87fc5 100755 --- a/MatFileHandler/MatFileHandler.csproj +++ b/MatFileHandler/MatFileHandler.csproj @@ -1,13 +1,13 @@  netstandard2.0;net461 - 1.3.0-beta3 + 1.3.0-beta4 MatFileHandler A library for reading and writing MATLAB .mat files. Alexander Luzgarev MatFileHandler provides a simple interface for reading and writing MATLAB .mat files (of so-called "Level 5") and extracting the contents of numerical arrays, logical arrays, sparse arrays, char arrays, cell arrays and structure arrays. Copyright 2017-2018 Alexander Luzgarev - https://raw.githubusercontent.com/mahalex/MatFileHandler/master/LICENSE.md + LICENSE.md https://github.com/mahalex/MatFileHandler First release. Matlab @@ -31,4 +31,7 @@ - \ No newline at end of file + + + +