Add explicit equality checks to DateFrames
This commit is contained in:
parent
d38e9bc0b4
commit
069ef96010
|
|
@ -3,7 +3,7 @@ using Microsoft.AspNetCore.Mvc;
|
||||||
|
|
||||||
namespace NejCommon.Models;
|
namespace NejCommon.Models;
|
||||||
|
|
||||||
public class DateOnlyFrame
|
public class DateOnlyFrame : IEquatable<DateOnlyFrame>
|
||||||
{
|
{
|
||||||
public DateOnlyFrame()
|
public DateOnlyFrame()
|
||||||
{
|
{
|
||||||
|
|
@ -40,4 +40,18 @@ public class DateOnlyFrame
|
||||||
{
|
{
|
||||||
return new DateTimeFrame(fromDate.ToDateTime(TimeOnly.MinValue), toDate.ToDateTime(TimeOnly.MaxValue));
|
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);
|
||||||
}
|
}
|
||||||
|
|
@ -2,7 +2,7 @@ using System.Linq.Expressions;
|
||||||
using NejCommon.Utils;
|
using NejCommon.Utils;
|
||||||
|
|
||||||
namespace NejCommon.Models;
|
namespace NejCommon.Models;
|
||||||
public class DateTimeFrame
|
public class DateTimeFrame : IEquatable<DateTimeFrame>
|
||||||
{
|
{
|
||||||
public DateTimeFrame(){
|
public DateTimeFrame(){
|
||||||
|
|
||||||
|
|
@ -32,4 +32,17 @@ public class DateTimeFrame
|
||||||
{
|
{
|
||||||
return new DateOnlyFrame(FromDate.ToDateOnly(), ToDate.ToDateOnly());
|
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);
|
||||||
}
|
}
|
||||||
Loading…
Reference in New Issue
Block a user