Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix generate names for complex locations without date #582

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading