From cfb0f6ba774ab5a161adf135104b834d6e8b1214 Mon Sep 17 00:00:00 2001 From: Apollo3zehn Date: Wed, 13 Mar 2024 22:24:25 +0100 Subject: [PATCH] Prepare fixing .NET UTC parse error (Z is being ignored) --- .../StructuredFileDataSource.cs | 19 ++++++++++++++++--- .../DATABASES/K/DATA/2020-01-01T00-00-00Z.dat | 0 .../DATABASES/K/config.json | 14 ++++++++++++++ .../Nexus.Sources.StructuredFile.Tests.csproj | 1 + .../StructuredFileDataSourceTests.cs | 1 + 5 files changed, 32 insertions(+), 3 deletions(-) create mode 100644 tests/Nexus.Sources.StructuredFile.Tests/DATABASES/K/DATA/2020-01-01T00-00-00Z.dat create mode 100644 tests/Nexus.Sources.StructuredFile.Tests/DATABASES/K/config.json diff --git a/src/Nexus.Sources.StructuredFile/StructuredFileDataSource.cs b/src/Nexus.Sources.StructuredFile/StructuredFileDataSource.cs index e626d5a..cf83f5a 100644 --- a/src/Nexus.Sources.StructuredFile/StructuredFileDataSource.cs +++ b/src/Nexus.Sources.StructuredFile/StructuredFileDataSource.cs @@ -721,7 +721,16 @@ async Task IDataSource.ReadAsync( // get all candidate folders var candidateFolders = fileSource.PathSegments.Length >= 1 - ? GetCandidateFolders(rootPath, default, begin, end, fileSource, fileSource.PathSegments, cancellationToken) + + ? GetCandidateFolders( + rootPath, + default, + begin, + end, + fileSource, + fileSource.PathSegments, + cancellationToken) + : new List<(string, DateTime)>() { (rootPath, default) }; return candidateFolders.SelectMany(currentFolder => @@ -731,7 +740,11 @@ async Task IDataSource.ReadAsync( var candidateFiles = filePaths .Select(filePath => { - var success = TryGetFileBeginByPath(filePath, fileSource, out var fileBegin, folderBegin: currentFolder.DateTime); + var success = TryGetFileBeginByPath( + filePath, + fileSource, + out var fileBegin, + folderBegin: currentFolder.DateTime); return (success, filePath, fileBegin); }) @@ -952,7 +965,7 @@ private static DateTime GetFolderBegin_AnyKind(string filePath, FileSource fileS var folderBegin = default(DateTime); var pathSegments = filePath - .Split('/', '\\'); + .Split('/', '\\'); pathSegments = pathSegments .Skip(pathSegments.Length - fileSource.PathSegments.Length - 1) diff --git a/tests/Nexus.Sources.StructuredFile.Tests/DATABASES/K/DATA/2020-01-01T00-00-00Z.dat b/tests/Nexus.Sources.StructuredFile.Tests/DATABASES/K/DATA/2020-01-01T00-00-00Z.dat new file mode 100644 index 0000000..e69de29 diff --git a/tests/Nexus.Sources.StructuredFile.Tests/DATABASES/K/config.json b/tests/Nexus.Sources.StructuredFile.Tests/DATABASES/K/config.json new file mode 100644 index 0000000..d2bd325 --- /dev/null +++ b/tests/Nexus.Sources.StructuredFile.Tests/DATABASES/K/config.json @@ -0,0 +1,14 @@ +{ + "/A/B/C": { + "default": [ + { + "PathSegments": [ + "'DATA'" + ], + "FileTemplate": "yyyy-MM-ddTHH-mm-ssZ'.dat'", + "FilePeriod": "1.00:00:00", + "UtcOffset": "00:00:00" + } + ] + } +} \ No newline at end of file diff --git a/tests/Nexus.Sources.StructuredFile.Tests/Nexus.Sources.StructuredFile.Tests.csproj b/tests/Nexus.Sources.StructuredFile.Tests/Nexus.Sources.StructuredFile.Tests.csproj index 7c03c3d..c5fa6d6 100644 --- a/tests/Nexus.Sources.StructuredFile.Tests/Nexus.Sources.StructuredFile.Tests.csproj +++ b/tests/Nexus.Sources.StructuredFile.Tests/Nexus.Sources.StructuredFile.Tests.csproj @@ -12,6 +12,7 @@ all runtime; build; native; contentfiles; analyzers + diff --git a/tests/Nexus.Sources.StructuredFile.Tests/StructuredFileDataSourceTests.cs b/tests/Nexus.Sources.StructuredFile.Tests/StructuredFileDataSourceTests.cs index 0aa536b..92d9915 100644 --- a/tests/Nexus.Sources.StructuredFile.Tests/StructuredFileDataSourceTests.cs +++ b/tests/Nexus.Sources.StructuredFile.Tests/StructuredFileDataSourceTests.cs @@ -49,6 +49,7 @@ public async Task CanProvideFirstFile() [InlineData("DATABASES/H", "2019-12-31T12-00-00Z", "2020-01-02T00-20-00Z")] [InlineData("DATABASES/I", "2019-12-31T23-55-00Z", "2020-01-01T00-15-00Z")] [InlineData("DATABASES/J", "2020-01-01T00-00-00Z", "2020-01-05T00-00-00Z")] + [InlineData("DATABASES/K", "2020-01-01T00-00-00Z", "2020-01-02T00-00-00Z")] public async Task CanProvideTimeRange(string root, string expectedBeginString, string expectedEndString) { var expectedBegin = DateTime.ParseExact(expectedBeginString, "yyyy-MM-ddTHH-mm-ssZ", null, DateTimeStyles.AdjustToUniversal);