Support for localizing datetimes base on browser's timezone

This commit is contained in:
rockstardev 2018-05-26 09:32:20 -05:00 committed by nicolas.dorier
parent 556082c4c9
commit 63ec832667
6 changed files with 22 additions and 7 deletions

View file

@ -425,7 +425,7 @@ namespace BTCPayServer.Controllers
{
Status = invoice.Status + (invoice.ExceptionStatus == null ? string.Empty : $" ({invoice.ExceptionStatus})"),
ShowCheckout = invoice.Status == "new",
Date = (DateTimeOffset.UtcNow - invoice.InvoiceTime).Prettify() + " ago",
Date = invoice.InvoiceTime,
InvoiceId = invoice.Id,
OrderId = invoice.OrderId ?? string.Empty,
RedirectUrl = invoice.RedirectURL ?? string.Empty,

View file

@ -33,10 +33,7 @@ namespace BTCPayServer.Models.InvoicingModels
public class InvoiceModel
{
public string Date
{
get; set;
}
public DateTimeOffset Date { get; set; }
public string OrderId { get; set; }
public string RedirectUrl { get; set; }

View file

@ -66,7 +66,7 @@
@foreach(var invoice in Model.Invoices)
{
<tr>
<td>@invoice.Date</td>
<td>@invoice.Date.BrowserDate()</td>
<td>
@if(invoice.RedirectUrl != string.Empty)
{

View file

@ -1,7 +1,9 @@
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Html;
using Microsoft.AspNetCore.Mvc.ViewFeatures;
namespace BTCPayServer.Views
@ -22,5 +24,11 @@ namespace BTCPayServer.Views
var activePage = (T)viewData[ACTIVE_PAGE_KEY];
return page.Equals(activePage) ? "active" : null;
}
public static HtmlString BrowserDate(this DateTimeOffset date)
{
var hello = date.ToString("o", CultureInfo.InvariantCulture);
return new HtmlString($"<span class='localizeDate'>{hello}</span>");
}
}
}

View file

@ -18,7 +18,8 @@
"wwwroot/vendor/jquery-easing/jquery.easing.js",
"wwwroot/vendor/scrollreveal/scrollreveal.min.js",
"wwwroot/vendor/magnific-popup/jquery.magnific-popup.js",
"wwwroot/vendor/bootstrap4-creativestart/*.js"
"wwwroot/vendor/bootstrap4-creativestart/*.js",
"wwwroot/main/**/*.js"
]
},
{

View file

@ -0,0 +1,9 @@
$(function () {
$(".localizeDate").each(function (index) {
var serverDate = $(this).text();
var localDate = new Date(serverDate);
var dateString = localDate.toLocaleDateString() + " " + localDate.toLocaleTimeString();
$(this).text(dateString);
});
});