From c72300c1680c2fb6690a1e5644ab996a77bd1b24 Mon Sep 17 00:00:00 2001 From: Tobias Klika Date: Sat, 12 Feb 2022 02:40:18 +0100 Subject: [PATCH] daterange format --- zero.Core/Utils/DateRange.cs | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/zero.Core/Utils/DateRange.cs b/zero.Core/Utils/DateRange.cs index f289e1c5..a78eec5a 100644 --- a/zero.Core/Utils/DateRange.cs +++ b/zero.Core/Utils/DateRange.cs @@ -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); + } } \ No newline at end of file