From 2fbd45d643de4095b1476a716930dc920c2d1709 Mon Sep 17 00:00:00 2001 From: Alexander Luzgarev Date: Mon, 4 Mar 2019 22:04:06 +0100 Subject: [PATCH 1/5] Handle unrepresentable datetimes --- MatFileHandler.Tests/MatFileReaderTests.cs | 13 +++++++++++++ .../test-data/good/datetime-unrepresentable.mat | Bin 0 -> 520 bytes MatFileHandler/DatetimeAdapter.cs | 13 ++++++++++++- 3 files changed, 25 insertions(+), 1 deletion(-) create mode 100644 MatFileHandler.Tests/test-data/good/datetime-unrepresentable.mat 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 0000000000000000000000000000000000000000..998807687907cc870b5649d985030f640f64e874 GIT binary patch literal 520 zcmeZu4DoSvQZUssQ1EpO(M`+DN!3vZ$Vn_o%P-2cQV4Jk_w+L}(NS?&W2{7Gv?%zR!VxtLX1Y1_6w_Mgq*s5TsFR(lH*^)MKRWXqz zVn>fVf6Z2S>3)O#;o&zeoy}M36Arw6&z$jU=7OX%0j6>a-<>}41V}hMO;k|bs3PdH zWLnCzWkyS$PBWMiVwfVfo5A(Z=OQi14UB4Q7OiLyyG%Z@o>lqX52x$>dGgyzjvZ*2b?(B~VuMN3 z{B|y^aaCYDsvyFkEW~D@ERxdCILSJ);D>x#Kf~0og+>p*iwjR-y>$IxgZ+JXg9Xd} Wb8KK1_<66n(dwrh3xipq&Q1W?`NJ{* literal 0 HcmV?d00001 diff --git a/MatFileHandler/DatetimeAdapter.cs b/MatFileHandler/DatetimeAdapter.cs index c86371f..cbc5e3f 100644 --- a/MatFileHandler/DatetimeAdapter.cs +++ b/MatFileHandler/DatetimeAdapter.cs @@ -57,6 +57,17 @@ namespace MatFileHandler /// /// Indices. /// Value converted to . - 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); + } + } } } \ No newline at end of file -- 2.45.2 From ada4005cab9fea4ec0d2a3826eb4e5e999309896 Mon Sep 17 00:00:00 2001 From: Alexander Luzgarev Date: Mon, 4 Mar 2019 22:07:57 +0100 Subject: [PATCH 2/5] Version bump --- MatFileHandler/MatFileHandler.csproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/MatFileHandler/MatFileHandler.csproj b/MatFileHandler/MatFileHandler.csproj index 7152830..1be2c6d 100755 --- a/MatFileHandler/MatFileHandler.csproj +++ b/MatFileHandler/MatFileHandler.csproj @@ -1,7 +1,7 @@  netstandard2.0;net461 - 1.3.0-beta3 + 1.3.0-beta4 MatFileHandler A library for reading and writing MATLAB .mat files. Alexander Luzgarev -- 2.45.2 From 51ec4c00bb0da97e6a064b43bb38849f7f617556 Mon Sep 17 00:00:00 2001 From: Alexander Luzgarev Date: Mon, 4 Mar 2019 22:11:09 +0100 Subject: [PATCH 3/5] Add license file to the solution --- MatFileHandler.sln | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) 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 -- 2.45.2 From 4999590eace6d9442615debd483ec200be996d49 Mon Sep 17 00:00:00 2001 From: Alexander Luzgarev Date: Mon, 4 Mar 2019 22:16:51 +0100 Subject: [PATCH 4/5] Replace license url with license file --- MatFileHandler/MatFileHandler.csproj | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/MatFileHandler/MatFileHandler.csproj b/MatFileHandler/MatFileHandler.csproj index 1be2c6d..6e87fc5 100755 --- a/MatFileHandler/MatFileHandler.csproj +++ b/MatFileHandler/MatFileHandler.csproj @@ -7,7 +7,7 @@ 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 + + + + -- 2.45.2 From 986d4b157ee191651fdd1f501007e7c1dfc0914b Mon Sep 17 00:00:00 2001 From: Alexander Luzgarev Date: Mon, 4 Mar 2019 22:18:52 +0100 Subject: [PATCH 5/5] Update XML documentation --- MatFileHandler/DatetimeAdapter.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/MatFileHandler/DatetimeAdapter.cs b/MatFileHandler/DatetimeAdapter.cs index cbc5e3f..bdac59f 100644 --- a/MatFileHandler/DatetimeAdapter.cs +++ b/MatFileHandler/DatetimeAdapter.cs @@ -56,7 +56,7 @@ namespace MatFileHandler /// Gets values of datetime object at given position in the array converted to . /// /// Indices. - /// Value converted to . + /// Value converted to ; null if the resulting value is unrepresentable. public DateTimeOffset? this[params int[] list] { get -- 2.45.2