Files
TimetableDesigner/TimetableDesigner.Core/TimetableSpan.cs

76 lines
1.9 KiB
C#
Raw Normal View History

2023-03-12 12:32:26 +01:00
using System;
namespace TimetableDesigner.Core
{
[Serializable]
2023-03-12 17:52:17 +01:00
public class TimetableSpan
2023-03-12 12:32:26 +01:00
{
#region PROPERTIES
public TimeOnly From { get; private set; }
public TimeOnly To { get; private set; }
#endregion
#region CONSTRUCTORS
2023-03-12 17:52:17 +01:00
public TimetableSpan(TimeOnly from, TimeOnly to)
2023-03-12 12:32:26 +01:00
{
if (to <= from)
{
throw new ArgumentException("\"to\" cannot be less or equal to \"from\"");
}
From = from;
To = to;
}
#endregion
#region PUBLIC METHODS
2023-03-12 17:52:17 +01:00
internal TimetableSpansCollision CheckCollision(TimetableSpan slot)
2023-03-12 12:32:26 +01:00
{
if (slot.To <= this.From)
{
2023-03-12 17:52:17 +01:00
return TimetableSpansCollision.CheckedSlotBefore;
2023-03-12 12:32:26 +01:00
}
else if (this.To <= slot.From)
{
2023-03-12 17:52:17 +01:00
return TimetableSpansCollision.CheckedSlotAfter;
2023-03-12 12:32:26 +01:00
}
else
{
if (this.From < slot.From && slot.To < this.To)
{
2023-03-12 17:52:17 +01:00
return TimetableSpansCollision.CheckedSlotIn;
2023-03-12 12:32:26 +01:00
}
else if (this.From < slot.From && slot.From < this.To && this.To < slot.To)
{
2023-03-12 17:52:17 +01:00
return TimetableSpansCollision.CheckedSlotFromIn;
2023-03-12 12:32:26 +01:00
}
else if (slot.From < this.From && this.From < slot.To && slot.To < this.To)
{
2023-03-12 17:52:17 +01:00
return TimetableSpansCollision.CheckedSlotToIn;
2023-03-12 12:32:26 +01:00
}
else
{
throw new ArgumentException("Unknown collision");
}
}
}
2023-03-12 17:52:17 +01:00
public override bool Equals(object? obj) => obj is TimetableSpan slot && From == slot.From && To == slot.To;
2023-03-12 12:32:26 +01:00
public override int GetHashCode() => HashCode.Combine(From, To);
public override string? ToString() => $"{From}-{To}";
#endregion
}
}