Date segment intersection judgment method, date intersection judgment
Two days ago, I encountered an intersection problem. An activity can be held only once in a period of time. You need to determine whether the activity time range already exists. Then, I listed the following expression:
------------------------ Original activity time ------------------------------
Time period
Start a1
End a1
Time period B
Start b1
End b2
Time period c
Start c1
End c2
------------------------------------------------------
List <date> activityList = new List <date> {a, B, c}
New activity release time
Time period n
Start n1
End n2
Foreach (var item in activityList)
{
// The intersection of time period n and time period item appears when n2> = item1 & n1 <= item2
If (n2> = item1 & n1 <= item2)
{
// Intersection time. the start time is set to begin and the end time is set to a small value.
}
}
It's quite easy to sort it out.