Basic Date rules
This commit is contained in:
@@ -0,0 +1,22 @@
|
|||||||
|
using AipsCore.Domain.Abstract.Rule;
|
||||||
|
|
||||||
|
namespace AipsCore.Domain.Common.Validation.Rules;
|
||||||
|
|
||||||
|
public class DateInFutureRule : AbstractRule
|
||||||
|
{
|
||||||
|
private readonly DateTime _date;
|
||||||
|
private readonly DateTime _now;
|
||||||
|
|
||||||
|
public DateInFutureRule(DateTime date)
|
||||||
|
{
|
||||||
|
_date = date;
|
||||||
|
_now = DateTime.Now;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override string ErrorCode => "date_in_future";
|
||||||
|
protected override string ErrorMessage => "Date must be in the future";
|
||||||
|
public override bool Validate()
|
||||||
|
{
|
||||||
|
return _date > _now;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,22 @@
|
|||||||
|
using AipsCore.Domain.Abstract.Rule;
|
||||||
|
|
||||||
|
namespace AipsCore.Domain.Common.Validation.Rules;
|
||||||
|
|
||||||
|
public class DateInPastRule : AbstractRule
|
||||||
|
{
|
||||||
|
private readonly DateTime _date;
|
||||||
|
private readonly DateTime _now;
|
||||||
|
|
||||||
|
public DateInPastRule(DateTime date)
|
||||||
|
{
|
||||||
|
_date = date;
|
||||||
|
_now = DateTime.Now;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override string ErrorCode => "date_in_past";
|
||||||
|
protected override string ErrorMessage => "Date must be in the past";
|
||||||
|
public override bool Validate()
|
||||||
|
{
|
||||||
|
return _date < _now;
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user