From 31d9b133e80234c619579a3c526c636287d2a78c Mon Sep 17 00:00:00 2001 From: Alex Zaytsev Date: Fri, 28 Jun 2024 17:06:11 +1000 Subject: [PATCH] Fix locations without date --- projects/GKCore/GDModel/GDMLocationRecord.cs | 6 ++++-- .../GKTests/GDModel/GDMLocationRecordTests.cs | 19 +++++++++++++++++++ 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/projects/GKCore/GDModel/GDMLocationRecord.cs b/projects/GKCore/GDModel/GDMLocationRecord.cs index 198fb7bed..567b34ef4 100644 --- a/projects/GKCore/GDModel/GDMLocationRecord.cs +++ b/projects/GKCore/GDModel/GDMLocationRecord.cs @@ -192,8 +192,10 @@ public GDMList GetFullNames(GDMTree tree, ATDEnumeration atdEnu var topNames = topLoc.GetFullNames(tree, atdEnum, abbreviations); for (int i = 0; i < topNames.Count; i++) { var topName = topNames[i]; + var topNameDate = topName.Date.Value; + var topLevelDate = topLevel.Date.Value; - var interDate = GDMCustomDate.GetIntersection(topLevel.Date.Value, topName.Date.Value); + var interDate = GDMCustomDate.GetIntersection(topLevelDate, topNameDate); if (!interDate.IsEmpty()) { string tnVal = (abbreviations && !string.IsNullOrEmpty(topName.Abbreviation)) ? topName.Abbreviation : topName.StringValue; topBuffer.Add(new GDMLocationName(tnVal, interDate)); @@ -240,7 +242,7 @@ public GDMList GetFullNames(GDMTree tree, ATDEnumeration atdEnu } } - if (!locDate.IsEmpty()) { + if (topBuffer.Count == 0 || !locDate.IsEmpty()) { result.Add(new GDMLocationName(nVal, locDate)); } } diff --git a/projects/GKTests/GDModel/GDMLocationRecordTests.cs b/projects/GKTests/GDModel/GDMLocationRecordTests.cs index ffb490d4e..248245c2c 100644 --- a/projects/GKTests/GDModel/GDMLocationRecordTests.cs +++ b/projects/GKTests/GDModel/GDMLocationRecordTests.cs @@ -502,6 +502,25 @@ public void Test_VyatkaProvince_MissingLocationName() , result); } + [Test] + public void Test_LocationsWithoutDates() + { + var tree = new GDMTree(); + var locRus = tree.CreateLocation(); + locRus.LocationName = "Россия"; + + var locMoscow = tree.CreateLocation(); + locMoscow.LocationName = "Москва"; + locMoscow.TopLevels.Add(new GDMLocationLink { XRef = locRus.XRef }); + + var names = locMoscow.GetFullNames(tree, ATDEnumeration.fLtS); + var result = string.Join("\n", names.Select(x => string.Format("'{0}': '{1}'", x.Date.ToString(), x.StringValue))); + + Assert.AreEqual( + "'': 'Москва'" + , result); + } + [Test] public void Test_DateIntersections() {