diff --git a/projects/GKCore/GDModel/GDMLocationRecord.cs b/projects/GKCore/GDModel/GDMLocationRecord.cs index e74fff6d1..4b6439084 100644 --- a/projects/GKCore/GDModel/GDMLocationRecord.cs +++ b/projects/GKCore/GDModel/GDMLocationRecord.cs @@ -20,6 +20,7 @@ using System; using System.Collections.Generic; +using System.Linq; using GDModel.Providers.GEDCOM; using GKCore.Calendar; using GKCore.Options; @@ -207,6 +208,8 @@ public GDMList GetFullNames(GDMTree tree, ATDEnumeration atdEnu } } + topBuffer = topBuffer.OrderByDescending(x => x.Date).ToList(); + // search of intersections of location names and intersections of top levels/names var q = new Queue(fNames); while (q.Count>0) { @@ -223,7 +226,7 @@ public GDMList GetFullNames(GDMTree tree, ATDEnumeration atdEnu if (!interDate.IsEmpty()) { string newName = (atdEnum == ATDEnumeration.fLtS) ? topName + ", " + nVal : nVal + ", " + topName; result.Add(new GDMLocationName(newName, interDate)); - var differences = GDMCustomDate.GetDifference(topDate, locName.Date.Value); + var differences = GDMCustomDate.GetDifference(interDate, locName.Date.Value); foreach (var difference in differences) { if (!difference.IsEmpty()) { q.Enqueue(new GDMLocationName(nVal, difference)); @@ -236,12 +239,17 @@ public GDMList GetFullNames(GDMTree tree, ATDEnumeration atdEnu } if (!wasJoin) { - result.Add(new GDMLocationName(nVal, locName.Date.Value)); + result.Add(locName); } } } - return result; + var gdmLocationNames = new GDMList(); + foreach (var name in result.OrderBy(x => x.Date)) { + gdmLocationNames.Add(name); + } + + return gdmLocationNames; } public string GetNameByDate(GDMCustomDate date, ATDEnumeration atdEnum, bool full = false) diff --git a/projects/GKTests/GDModel/GDMLocationRecordTests.cs b/projects/GKTests/GDModel/GDMLocationRecordTests.cs index b85f24348..27480f2e9 100644 --- a/projects/GKTests/GDModel/GDMLocationRecordTests.cs +++ b/projects/GKTests/GDModel/GDMLocationRecordTests.cs @@ -422,8 +422,8 @@ public void Test_Carbuna2() ussr.AddLocName("СССР", "FROM 30 DEC 1922 TO 26 DEC 1991"); var moldova = tree.CreateLocation(); - moldova.AddLocName("Молдавская ССР", "FROM 2 AUG 1940 TO 27 AUG 1991"); moldova.AddLocName("Молдова", "FROM 28 AUG 1991"); + moldova.AddLocName("Молдавская ССР", "FROM 2 AUG 1940 TO 27 AUG 1991"); moldova.AddLocLink(ussr, "FROM 2 AUG 1940 TO 27 AUG 1991"); var carbuna = tree.CreateLocation();