Método que las utiliza:
static bool RangosSuperpuestos(DataRow dr, string pHoraInicio, string pHoraFin)
{
DateTime horaIniciodr = DateTime.Parse(dr["Inicio"].ToString());
DateTime horaFindr = DateTime.Parse(dr["Fin"].ToString());
DateTime horaInicio = DateTime.Parse(pHoraInicio);
DateTime horaFin = DateTime.Parse(pHoraFin);
return Range.Overlap(new Range(horaIniciodr, horaFindr), new Range(horaInicio, horaFin));
}
Clases Auxiliares:
class Range
{
public readonly T Start;
public readonly T End;
public Range(T start, T end)
{
Start = start;
End = end;
}
}
static class Range
{
public static bool Overlap(Range left, Range right) where T : IComparable
{
if (left.Start.CompareTo(right.Start) == 0)
{
return true;
}
else if (left.Start.CompareTo(right.Start) > 0)
{
return left.Start.CompareTo(right.End) <= 0;
}
else
{
return right.Start.CompareTo(left.End) <= 0;
}
}
}