Skip to content

Commit

Permalink
Merge pull request #579 from hazzik/fix-GetIntersection
Browse files Browse the repository at this point in the history
Fix intersection of open periods
  • Loading branch information
Serg-Norseman authored Jun 26, 2024
2 parents 2d307e3 + e962b41 commit 894a868
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
2 changes: 1 addition & 1 deletion projects/GKCore/GDModel/GDMCustomDate.cs
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ public static GDMDatePeriod GetIntersection(GDMCustomDate range1, GDMCustomDate
GDMDate smallestEnd = r1end.IsEmpty() ? r2end : (r2end.IsEmpty() ? r1end : (r1end.CompareTo(r2end) < 0) ? r1end : r2end);

// no intersection
if (greatestStart.CompareTo(smallestEnd) > 0) {
if (greatestStart.CompareTo(smallestEnd) > 0 && !greatestStart.IsEmpty() && !smallestEnd.IsEmpty()) {
return GDMDatePeriod.Empty;
}

Expand Down
4 changes: 4 additions & 0 deletions projects/GKTests/GDModel/GDMLocationRecordTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -406,6 +406,10 @@ public void Test_DateIntersections()

Assert.AreEqual("FROM 1782 TO 1834", GDMCustomDate.GetIntersection(GetRange("FROM 1782"), GetRange("TO 1834")).StringValue);
Assert.AreEqual("FROM 1782 TO 1834", GDMCustomDate.GetIntersection(GetRange("TO 1834"), GetRange("FROM 1782")).StringValue);
Assert.AreEqual("FROM 1782", GDMCustomDate.GetIntersection(GetRange("FROM 1782"), GetRange("FROM 1782")).StringValue);
Assert.AreEqual("FROM 1834", GDMCustomDate.GetIntersection(GetRange("FROM 1782"), GetRange("FROM 1834")).StringValue);
Assert.AreEqual("TO 1782", GDMCustomDate.GetIntersection(GetRange("TO 1782"), GetRange("TO 1782")).StringValue);
Assert.AreEqual("TO 1782", GDMCustomDate.GetIntersection(GetRange("TO 1782"), GetRange("TO 1834")).StringValue);

Assert.AreEqual("", GDMCustomDate.GetIntersection(GetRange("FROM 1858"), GetRange("TO 1834")).StringValue); // no intersects
Assert.AreEqual("", GDMCustomDate.GetIntersection(GetRange("TO 1834"), GetRange("FROM 1858")).StringValue); // no intersects
Expand Down

0 comments on commit 894a868

Please sign in to comment.