Вы создаете собственный класс для получения информации о временных периодах, например:
public class TimePeriod
{
public DateTime Start { get; set; }
public DateTime End { get; set; }
public TimePeriod(DateTime start, DateTime end)
{
if( start > end)
throw new InvalidArgumentException();
Start = start;
End = end;
}
public bool Overlaps(TimePeriod tp)
{
// it's enough for one's period start or end to fall between the other's start and end to overlap
if ((Start > tp.Start && Start < tp.End ) ||
(End > tp.Start && End < tp.End) ||
(tp.Start > Start && tp.Start < End) ||
(tp.End > Start && tp.End < End) )
return true;
else
return false;
}
}
Тогда использование становится чрезвычайно простым:
TimePeriod tp1 = new TimePeriod(dt1, dt2);
TimePeriod tp2 = new TimePeriod(dt3, dt4);
var overlaps = tp1.Overlaps(tp2);