diff --git a/BTCPayServer/Extensions.cs b/BTCPayServer/Extensions.cs index e6e7e3520..151042737 100644 --- a/BTCPayServer/Extensions.cs +++ b/BTCPayServer/Extensions.cs @@ -36,28 +36,6 @@ namespace BTCPayServer { public static class Extensions { - public static string Prettify(this TimeSpan timeSpan) - { - if (timeSpan.TotalMinutes < 1) - { - return $"{(int)timeSpan.TotalSeconds} second{Plural((int)timeSpan.TotalSeconds)}"; - } - if (timeSpan.TotalHours < 1) - { - return $"{(int)timeSpan.TotalMinutes} minute{Plural((int)timeSpan.TotalMinutes)}"; - } - if (timeSpan.Days < 1) - { - return $"{(int)timeSpan.TotalHours} hour{Plural((int)timeSpan.TotalHours)}"; - } - return $"{(int)timeSpan.TotalDays} day{Plural((int)timeSpan.TotalDays)}"; - } - - private static string Plural(int totalDays) - { - return totalDays > 1 ? "s" : string.Empty; - } - public static string PrettyPrint(this TimeSpan expiration) { StringBuilder builder = new StringBuilder(); diff --git a/BTCPayServer/Views/Invoice/ListInvoices.cshtml b/BTCPayServer/Views/Invoice/ListInvoices.cshtml index e7bc473d9..724da6feb 100644 --- a/BTCPayServer/Views/Invoice/ListInvoices.cshtml +++ b/BTCPayServer/Views/Invoice/ListInvoices.cshtml @@ -66,7 +66,7 @@ @foreach(var invoice in Model.Invoices) { - @invoice.Date.ToBrowserDate() + @invoice.Date.ToBrowserAgo() @if(invoice.RedirectUrl != string.Empty) { diff --git a/BTCPayServer/Views/Server/Rates.cshtml b/BTCPayServer/Views/Server/Rates.cshtml index bbf407366..1dcf9bea6 100644 --- a/BTCPayServer/Views/Server/Rates.cshtml +++ b/BTCPayServer/Views/Server/Rates.cshtml @@ -40,7 +40,7 @@ - + @@ -48,7 +48,7 @@ - +
Quota period@Model.RateLimits.TotalPeriod.Prettify()@Model.RateLimits.TotalPeriod.TimeString()
Requests quota
Quota reset in@Model.RateLimits.CounterReset.Prettify()@Model.RateLimits.CounterReset.TimeString()
} diff --git a/BTCPayServer/Views/ViewsRazor.cs b/BTCPayServer/Views/ViewsRazor.cs index 6affde624..fef222f33 100644 --- a/BTCPayServer/Views/ViewsRazor.cs +++ b/BTCPayServer/Views/ViewsRazor.cs @@ -30,5 +30,33 @@ namespace BTCPayServer.Views var hello = date.ToString("o", CultureInfo.InvariantCulture); return new HtmlString($"{hello}"); } + + public static string ToBrowserAgo(this DateTimeOffset date) + { + var formatted = (DateTimeOffset.UtcNow - date).TimeString() + " ago"; + return formatted; + } + + public static string TimeString(this TimeSpan timeSpan) + { + if (timeSpan.TotalMinutes < 1) + { + return $"{(int)timeSpan.TotalSeconds} second{Plural((int)timeSpan.TotalSeconds)}"; + } + if (timeSpan.TotalHours < 1) + { + return $"{(int)timeSpan.TotalMinutes} minute{Plural((int)timeSpan.TotalMinutes)}"; + } + if (timeSpan.Days < 1) + { + return $"{(int)timeSpan.TotalHours} hour{Plural((int)timeSpan.TotalHours)}"; + } + return $"{(int)timeSpan.TotalDays} day{Plural((int)timeSpan.TotalDays)}"; + } + + private static string Plural(int totalDays) + { + return totalDays > 1 ? "s" : string.Empty; + } } }