Merge pull request #242 from jeking3/coverity-255065

issue-204: period::intersects incorrect for empty periods
This commit is contained in:
Jeff Garland
2025-07-06 18:06:39 -07:00
committed by GitHub
2 changed files with 5 additions and 7 deletions
+1 -3
View File
@@ -299,9 +299,7 @@ namespace date_time {
inline BOOST_CXX14_CONSTEXPR
bool period<point_rep,duration_rep>::intersects(const period<point_rep,duration_rep>& other) const
{
return ( contains(other.begin_) ||
other.contains(begin_) ||
((other.begin_ < begin_) && (other.last_ >= begin_)));
return !is_null() && !other.is_null() && (begin_ < other.end()) && (other.begin_ < end());
}
//! Returns the period of intersection or invalid range no intersection
+4 -4
View File
@@ -125,8 +125,8 @@ int main(){
check("Contains rep", !zero_len.contains(3));
check("Contains period (not)", !zero_len.contains(a_period(5,8)));
check("Contains period", p1.contains(zero_len));
check("Intersects", zero_len.intersects(p1));
check("Intersects", p1.intersects(zero_len));
check("Intersects", !zero_len.intersects(p1));
check("Intersects", !p1.intersects(zero_len));
check("Adjacent", zero_len.is_adjacent(a_period(-10,3)));
check("Adjacent", a_period(-10,3).is_adjacent(zero_len));
check("Intersection", (zero_len.intersection(p1) == zero_len));
@@ -146,8 +146,8 @@ int main(){
check("Contains rep in-between (always false)", !null_per.contains(3));
check("Contains period (not)", !null_per.contains(a_period(7,9)));
check("Contains period", p1.contains(null_per));
check("Intersects", null_per.intersects(p1));
check("Intersects", p1.intersects(null_per));
check("Intersects", !null_per.intersects(p1));
check("Intersects", !p1.intersects(null_per));
check("Adjacent", null_per.is_adjacent(a_period(-10,5)));
check("Adjacent", null_per.is_adjacent(a_period(1,10)));