Files
mixtape/zero.Core/Utils/DateRange.cs
T

40 lines
803 B
C#
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
namespace zero.Utils;
public class DateRange
{
public DateTimeOffset? From { get; set; }
public DateTimeOffset? To { get; set; }
public bool IsWithin(DateTimeOffset date)
{
if (From.HasValue && date < From)
{
return false;
}
if (To.HasValue && date > To)
{
return false;
}
return true;
}
public string Format(string format)
{
if (!From.HasValue && !To.HasValue)
{
return null;
}
if (!From.HasValue && To.HasValue)
{
return "≤ " + To.Value.ToLocalTime().ToString(format);
}
if (From.HasValue && !To.HasValue)
{
return "≥ " + From.Value.ToLocalTime().ToString(format);
}
return From.Value.ToLocalTime().ToString(format) + " " + To.Value.ToLocalTime().ToString(format);
}
}