daterange format

This commit is contained in:
2022-02-12 02:40:18 +01:00
parent 050dbfe987
commit c72300c168
+20 -3
View File
@@ -1,6 +1,4 @@
using System;
namespace zero.Utils;
namespace zero.Utils;
public class DateRange
{
@@ -8,6 +6,7 @@ public class DateRange
public DateTimeOffset? To { get; set; }
public bool IsWithin(DateTimeOffset date)
{
if (From.HasValue && date < From)
@@ -20,4 +19,22 @@ public class DateRange
}
return true;
}
public string Format(string format)
{
if (!From.HasValue && !To.HasValue)
{
return null;
}
if (!From.HasValue && To.HasValue)
{
return "≤ " + To.Value.ToString(format);
}
if (From.HasValue && !To.HasValue)
{
return "≥ " + From.Value.ToString(format);
}
return From.Value.ToString(format) + " " + To.Value.ToString(format);
}
}