I have the following function:
public bool IsAvailableForTimeslot(DateTime start, DateTime end)
{
bool startOK = true;
bool endOK = true;
foreach (var slot in ReservedSlots)
{
if (slot.Item2.AddHours(6) > start)
{
startOK = false;
}
if (slot.Item1 < end && start < slot.Item2)
{
endOK = false;
}
}
if (startOK == true && endOK == true)
return true;
else
return false;
}
// List of Tuples with already reserved timeslots, Item1 being the start en 2 the end
public List<Tuple<DateTime, DateTime>> ReservedSlots { get; set; }
When startdates and times within the "ReservedSlots" list are the same year as the parameters, the function returns everything as normal, but when the year differs the function marks startOK as false.
More information: Let's say I have 4 vehicles with a "ReservedSlots" list.
demoVehicle0.ReservedSlots.Add(new Tuple<DateTime, DateTime>(new DateTime(2020, 1, 1, 12, 0, 0), new DateTime(2020, 1, 1, 20, 0, 0)));
demoVehicle0.ReservedSlots.Add(new Tuple<DateTime, DateTime>(new DateTime(2020, 1, 2, 3, 0, 0), new DateTime(2020, 1, 2, 13, 0, 0)));
// Works (returns false)
demoVehicle2.ReservedSlots.Add(new Tuple<DateTime, DateTime>(new DateTime(2020, 1, 1, 12, 0, 0), new DateTime(2020, 1, 1, 20, 0, 0)));
demoVehicle2.ReservedSlots.Add(new Tuple<DateTime, DateTime>(new DateTime(2020, 1, 2, 3, 0, 0), new DateTime(2020, 1, 2, 13, 0, 0)));
// Works (returns false)
demoVehicle3.ReservedSlots.Add(new Tuple<DateTime, DateTime>(new DateTime(2021, 1, 1, 1, 0, 0), new DateTime(2021, 1, 1, 5, 0, 0)));
// Doesnt work (returns false) if I change the year to 2020, it will work however
// timeslot is what is used in the parameters of the function above
var timeslot = new Tuple<DateTime, DateTime>(new DateTime(2020, 1, 1, 20, 0, 0), new DateTime(2020, 1, 2, 0, 0, 0));