diff --git a/BTCPayServer.Abstractions/Extensions/ViewsRazor.cs b/BTCPayServer.Abstractions/Extensions/ViewsRazor.cs index 623c946d3..7600efe63 100644 --- a/BTCPayServer.Abstractions/Extensions/ViewsRazor.cs +++ b/BTCPayServer.Abstractions/Extensions/ViewsRazor.cs @@ -14,6 +14,12 @@ namespace BTCPayServer.Abstractions.Extensions private const string ACTIVE_ID_KEY = "ActiveId"; private const string ActivePageClass = "active"; + public enum DateDisplayFormat + { + Localized, + Relative + } + public static void SetActivePage(this ViewDataDictionary viewData, T activePage, string title = null, string activeId = null) where T : IConvertible { @@ -86,18 +92,22 @@ namespace BTCPayServer.Abstractions.Extensions return categoryAndPageMatch && idMatch ? ActivePageClass : null; } - public static HtmlString ToBrowserDate(this DateTimeOffset date) + public static HtmlString ToBrowserDate(this DateTimeOffset date, DateDisplayFormat format = DateDisplayFormat.Localized) { - var displayDate = date.ToString("g", CultureInfo.InvariantCulture); + var relative = date.ToTimeAgo(); + var initial = format.ToString().ToLower(); var dateTime = date.ToString("s", CultureInfo.InvariantCulture); - return new HtmlString($""); + var displayDate = format == DateDisplayFormat.Relative ? relative : date.ToString("g", CultureInfo.InvariantCulture); + return new HtmlString($""); } - public static HtmlString ToBrowserDate(this DateTime date) + public static HtmlString ToBrowserDate(this DateTime date, DateDisplayFormat format = DateDisplayFormat.Localized) { - var displayDate = date.ToString("g", CultureInfo.InvariantCulture); + var relative = date.ToTimeAgo(); + var initial = format.ToString().ToLower(); var dateTime = date.ToString("s", CultureInfo.InvariantCulture); - return new HtmlString($""); + var displayDate = format == DateDisplayFormat.Relative ? relative : date.ToString("g", CultureInfo.InvariantCulture); + return new HtmlString($""); } public static string ToTimeAgo(this DateTimeOffset date) => (DateTimeOffset.UtcNow - date).ToTimeAgo(); diff --git a/BTCPayServer/Views/UIInvoice/ListInvoices.cshtml b/BTCPayServer/Views/UIInvoice/ListInvoices.cshtml index 05537fdc9..845a10f1a 100644 --- a/BTCPayServer/Views/UIInvoice/ListInvoices.cshtml +++ b/BTCPayServer/Views/UIInvoice/ListInvoices.cshtml @@ -282,9 +282,11 @@ - - Date - + +
+ Date + +
Order Id Invoice Id diff --git a/BTCPayServer/Views/UINotifications/Index.cshtml b/BTCPayServer/Views/UINotifications/Index.cshtml index 6c10c30da..e5f7311c2 100644 --- a/BTCPayServer/Views/UINotifications/Index.cshtml +++ b/BTCPayServer/Views/UINotifications/Index.cshtml @@ -39,9 +39,11 @@ } - - Date - + +
+ Date + +
Message Actions diff --git a/BTCPayServer/Views/UIWallets/WalletTransactions.cshtml b/BTCPayServer/Views/UIWallets/WalletTransactions.cshtml index 6b64d2d95..5bb841d45 100644 --- a/BTCPayServer/Views/UIWallets/WalletTransactions.cshtml +++ b/BTCPayServer/Views/UIWallets/WalletTransactions.cshtml @@ -206,9 +206,11 @@ - - Date - + +
+ Date + +
Label Transaction Id diff --git a/BTCPayServer/wwwroot/main/site.css b/BTCPayServer/wwwroot/main/site.css index bd5aa3b6b..ab8dd0cc2 100644 --- a/BTCPayServer/wwwroot/main/site.css +++ b/BTCPayServer/wwwroot/main/site.css @@ -96,14 +96,6 @@ a.unobtrusive-link { transform: rotate(-180deg); } -time[datetime] { - display: block; - max-width: 125px; - overflow: hidden; - white-space: nowrap; - text-overflow: ellipsis; -} - /* Badges */ .badge-new { background: #d4edda; diff --git a/BTCPayServer/wwwroot/main/site.js b/BTCPayServer/wwwroot/main/site.js index 4776ea600..c2d27a943 100644 --- a/BTCPayServer/wwwroot/main/site.js +++ b/BTCPayServer/wwwroot/main/site.js @@ -3,14 +3,14 @@ const flatpickrInstances = []; // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DateTimeFormat/DateTimeFormat const dtFormatOpts = { dateStyle: 'short', timeStyle: 'short' }; -const formatDateTimes = mode => { - if (!mode) mode = 'localized'; +const formatDateTimes = format => { // select only elements which haven't been initialized before, those without data-localized document.querySelectorAll("time[datetime]:not([data-localized])").forEach($el => { const date = new Date($el.getAttribute("datetime")); // initialize and set localized attribute $el.dataset.localized = new Intl.DateTimeFormat('default', dtFormatOpts).format(date); // set text to chosen mode + const mode = format || $el.dataset.initial; if ($el.dataset[mode]) $el.innerText = $el.dataset[mode]; }); }; @@ -139,7 +139,7 @@ document.addEventListener("DOMContentLoaded", () => { }); // Time Format - delegate('click', '#switchTimeFormat', switchTimeFormat); + delegate('click', '.switch-time-format', switchTimeFormat); // Theme Switch delegate('click', '.btcpay-theme-switch', e => {