public static void Main()
Console.WriteLine("Four case test:");
Console.WriteLine("Three case test:");
Console.WriteLine("Two case test:");
private static bool FourCaseTest(Span shift, Span person)
return person.Begin >= shift.Begin && person.Begin <= shift.End ||
person.End >= shift.Begin && person.End <= shift.End ||
person.Begin <= shift.Begin && person.End >= shift.End ||
person.Begin >= shift.Begin && person.End <= shift.End;
private static bool ThreeCaseTest(Span shift, Span person)
return person.Begin >= shift.Begin && person.Begin <= shift.End ||
person.End >= shift.Begin && person.End <= shift.End ||
person.Begin <= shift.Begin && person.End >= shift.End;
private static bool TwoCaseTest(Span shift, Span person)
return person.Begin <= shift.End && person.End >= shift.Begin;
private static void Test(Func<Span, Span, bool> test)
var shift = new Span(new DateTime(2000, 1, 1, 9, 0, 0), new DateTime(2000, 1, 1, 17, 0, 0));
result = test(shift, new Span(new DateTime(2000, 1, 1, 6, 0, 0), new DateTime(2000, 1, 1, 8, 0, 0)));
Console.WriteLine("Person works entirely before shift: " + result);
result = test(shift, new Span(new DateTime(2000, 1, 1, 6, 0, 0), new DateTime(2000, 1, 1, 10, 0, 0)));
Console.WriteLine("Person starts work before shift and ends during shift: " + result);
result = test(shift, new Span(new DateTime(2000, 1, 1, 6, 0, 0), new DateTime(2000, 1, 1, 18, 0, 0)));
Console.WriteLine("Person starts work before shift and ends after shift: " + result);
result = test(shift, new Span(new DateTime(2000, 1, 1, 10, 0, 0), new DateTime(2000, 1, 1, 16, 0, 0)));
Console.WriteLine("Person starts work after shift starts and ends before shift ends: " + result);
result = test(shift, new Span(new DateTime(2000, 1, 1, 10, 0, 0), new DateTime(2000, 1, 1, 18, 0, 0)));
Console.WriteLine("Person starts work after shift starts and ends after shift: " + result);
result = test(shift, new Span(new DateTime(2000, 1, 1, 18, 0, 0), new DateTime(2000, 1, 1, 20, 0, 0)));
Console.WriteLine("Person works entirely after shift: " + result);
public DateTime Begin { get; }
public DateTime End { get; }
public Span(DateTime begin, DateTime end)