Skip to content

Commit

Permalink
Merge pull request #582 from hazzik/fix-locations-without-dates
Browse files Browse the repository at this point in the history
Fix generate names for complex locations without date
  • Loading branch information
Serg-Norseman authored Jun 28, 2024
2 parents 68ce5ba + 31d9b13 commit e86aefa
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 2 deletions.
6 changes: 4 additions & 2 deletions projects/GKCore/GDModel/GDMLocationRecord.cs
Original file line number Diff line number Diff line change
Expand Up @@ -192,8 +192,10 @@ public GDMList<GDMLocationName> 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));
Expand Down Expand Up @@ -240,7 +242,7 @@ public GDMList<GDMLocationName> GetFullNames(GDMTree tree, ATDEnumeration atdEnu
}
}

if (!locDate.IsEmpty()) {
if (topBuffer.Count == 0 || !locDate.IsEmpty()) {
result.Add(new GDMLocationName(nVal, locDate));
}
}
Expand Down
19 changes: 19 additions & 0 deletions projects/GKTests/GDModel/GDMLocationRecordTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
{
Expand Down

0 comments on commit e86aefa

Please sign in to comment.