class Period {
public DateTime Start { get; set; }
public DateTime End { get; set; }
}
I'm having difficulty with boolean logic of comparing two Period objects
Suppose in DB I have the following Period object.
var periodInDb = new Period {
Start = DateTime.ParseExact("2022-12-18", "yyyy-MM-dd", CultureInfo.InvariantCulture);
End = DateTime.ParseExact("2023-01-11", "yyyy-MM-dd", CultureInfo.InvariantCulture);
};
I want to only add a new period if it doesn't fall in between the period above.
I have written out on paper some type of scenario dates that might get added, I might have missed some scenarios:
Start: 2022/12/18
End: 2023/01/11
Some scenario dates:
Start: 2022/12/19 ✔️
End: 2023/01/10 ❌
------------------
❌ Don't add because end date
falls between between 2022/12/18 - 2023/01/11
Start: 2022/12/19 ✔️
End: 2023/01/12 ✔️
------------------
❌ Don't add because start date
falls between 2022/12/18 - 2023/01/11
Start: 2022/12/17 ✔️
End: 2023/01/12 ✔️
------------------
❌ Don't add because part of start date and end date
falls outside of 2022/12/18 - 2023/01/11
Start: 2022/12/16 ✔️
End: 2023/12/17 ✔️
------------------
✔️ Add because start date and end date
falls outside of 2022/12/18 - 2023/01/11
How would I know if a period falls outside of another period?