diff --git a/Models/DateOnlyFrame.cs b/Models/DateOnlyFrame.cs index 4beddf8..fc6d6fb 100644 --- a/Models/DateOnlyFrame.cs +++ b/Models/DateOnlyFrame.cs @@ -3,7 +3,7 @@ using Microsoft.AspNetCore.Mvc; namespace NejCommon.Models; -public class DateOnlyFrame +public class DateOnlyFrame : IEquatable { public DateOnlyFrame() { @@ -40,4 +40,18 @@ public class DateOnlyFrame { return new DateTimeFrame(fromDate.ToDateTime(TimeOnly.MinValue), toDate.ToDateTime(TimeOnly.MaxValue)); } + + public bool Equals(DateOnlyFrame? other) + { + if (other is null) return false; + return this.fromDate == other.fromDate && this.toDate == other.toDate; + } + public override int GetHashCode() + => HashCode.Combine(fromDate, toDate); + + public static bool operator ==(DateOnlyFrame left, DateOnlyFrame right) + => left.Equals(right); + + public static bool operator !=(DateOnlyFrame left, DateOnlyFrame right) + => !left.Equals(right); } \ No newline at end of file diff --git a/Models/DateTimeFrame.cs b/Models/DateTimeFrame.cs index 09efea3..e319782 100644 --- a/Models/DateTimeFrame.cs +++ b/Models/DateTimeFrame.cs @@ -2,7 +2,7 @@ using System.Linq.Expressions; using NejCommon.Utils; namespace NejCommon.Models; -public class DateTimeFrame +public class DateTimeFrame : IEquatable { public DateTimeFrame(){ @@ -32,4 +32,17 @@ public class DateTimeFrame { return new DateOnlyFrame(FromDate.ToDateOnly(), ToDate.ToDateOnly()); } + public bool Equals(DateTimeFrame? other) + { + if (other is null) return false; + return this.FromDate == other.FromDate && this.ToDate == other.ToDate; + } + public override int GetHashCode() + => HashCode.Combine(FromDate, ToDate); + + public static bool operator ==(DateTimeFrame left, DateTimeFrame right) + => left.Equals(right); + + public static bool operator !=(DateTimeFrame left, DateTimeFrame right) + => !left.Equals(right); } \ No newline at end of file