Add explicit equality checks to DateFrames

This commit is contained in:
honzapatCZ 2026-08-07 23:34:46 +02:00
parent d38e9bc0b4
commit 069ef96010
2 changed files with 29 additions and 2 deletions

View File

@ -3,7 +3,7 @@ using Microsoft.AspNetCore.Mvc;
namespace NejCommon.Models;
public class DateOnlyFrame
public class DateOnlyFrame : IEquatable<DateOnlyFrame>
{
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);
}

View File

@ -2,7 +2,7 @@ using System.Linq.Expressions;
using NejCommon.Utils;
namespace NejCommon.Models;
public class DateTimeFrame
public class DateTimeFrame : IEquatable<DateTimeFrame>
{
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);
}