mirror of
https://github.com/aljazceru/btcpayserver.git
synced 2025-12-19 06:54:19 +01:00
Generalizing TimeSpan to Time Ago, reverting invoice list to ago
This commit is contained in:
committed by
nicolas.dorier
parent
d7a5021ed2
commit
d7fccae452
@@ -36,28 +36,6 @@ namespace BTCPayServer
|
|||||||
{
|
{
|
||||||
public static class Extensions
|
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)
|
public static string PrettyPrint(this TimeSpan expiration)
|
||||||
{
|
{
|
||||||
StringBuilder builder = new StringBuilder();
|
StringBuilder builder = new StringBuilder();
|
||||||
|
|||||||
@@ -66,7 +66,7 @@
|
|||||||
@foreach(var invoice in Model.Invoices)
|
@foreach(var invoice in Model.Invoices)
|
||||||
{
|
{
|
||||||
<tr>
|
<tr>
|
||||||
<td>@invoice.Date.ToBrowserDate()</td>
|
<td>@invoice.Date.ToBrowserAgo()</td>
|
||||||
<td>
|
<td>
|
||||||
@if(invoice.RedirectUrl != string.Empty)
|
@if(invoice.RedirectUrl != string.Empty)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -40,7 +40,7 @@
|
|||||||
<table class="table table-sm">
|
<table class="table table-sm">
|
||||||
<tr>
|
<tr>
|
||||||
<th>Quota period</th>
|
<th>Quota period</th>
|
||||||
<td>@Model.RateLimits.TotalPeriod.Prettify()</td>
|
<td>@Model.RateLimits.TotalPeriod.TimeString()</td>
|
||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
<th>Requests quota</th>
|
<th>Requests quota</th>
|
||||||
@@ -48,7 +48,7 @@
|
|||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
<th>Quota reset in</th>
|
<th>Quota reset in</th>
|
||||||
<td>@Model.RateLimits.CounterReset.Prettify()</td>
|
<td>@Model.RateLimits.CounterReset.TimeString()</td>
|
||||||
</tr>
|
</tr>
|
||||||
</table>
|
</table>
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -30,5 +30,33 @@ namespace BTCPayServer.Views
|
|||||||
var hello = date.ToString("o", CultureInfo.InvariantCulture);
|
var hello = date.ToString("o", CultureInfo.InvariantCulture);
|
||||||
return new HtmlString($"<span class='localizeDate'>{hello}</span>");
|
return new HtmlString($"<span class='localizeDate'>{hello}</span>");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user