using System.Linq.Expressions; using NejCommon.Utils; namespace NejCommon.Models; public class DateTimeFrame { public DateTimeFrame(){ } public DateTimeFrame(DateTime fromDate, DateTime toDate) { FromDate = fromDate; ToDate = toDate; } public DateTime FromDate { get; set; } = DateTime.MinValue; public DateTime ToDate { get; set; } = DateTime.MaxValue; public override string ToString() { var from = (FromDate == DateTime.MinValue) ? "" : ("-" + FromDate.ToShortDateString()); var to = (ToDate == DateTime.MaxValue) ? "" : ("-" + ToDate.ToShortDateString()); return $"{from}{to}"; } public static Expression> Conditional(Expression> dateAcessor, DateTimeFrame frame) { return e => dateAcessor.Compile()(e) >= frame.FromDate && dateAcessor.Compile()(e) <= frame.ToDate; } public DateOnlyFrame ToDateOnlyFrame() { return new DateOnlyFrame(FromDate.ToDateOnly(), ToDate.ToDateOnly()); } }