Teacher editor

This commit is contained in:
2023-03-12 17:52:17 +01:00
Unverified
parent 95364c8a31
commit 3cc4ea5b4b
28 changed files with 947 additions and 93 deletions

View File

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