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})"), Status = invoice.Status + (invoice.ExceptionStatus == null ? string.Empty : $" ({invoice.ExceptionStatus})"),
ShowCheckout = invoice.Status == "new", ShowCheckout = invoice.Status == "new",
Date = (DateTimeOffset.UtcNow - invoice.InvoiceTime).Prettify() + " ago", Date = invoice.InvoiceTime,
InvoiceId = invoice.Id, InvoiceId = invoice.Id,
OrderId = invoice.OrderId ?? string.Empty, OrderId = invoice.OrderId ?? string.Empty,
RedirectUrl = invoice.RedirectURL ?? string.Empty, RedirectUrl = invoice.RedirectURL ?? string.Empty,

View File

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

View File

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

View File

@@ -1,7 +1,9 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Globalization;
using System.Linq; using System.Linq;
using System.Threading.Tasks; using System.Threading.Tasks;
using Microsoft.AspNetCore.Html;
using Microsoft.AspNetCore.Mvc.ViewFeatures; using Microsoft.AspNetCore.Mvc.ViewFeatures;
namespace BTCPayServer.Views namespace BTCPayServer.Views
@@ -22,5 +24,11 @@ namespace BTCPayServer.Views
var activePage = (T)viewData[ACTIVE_PAGE_KEY]; var activePage = (T)viewData[ACTIVE_PAGE_KEY];
return page.Equals(activePage) ? "active" : null; 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/jquery-easing/jquery.easing.js",
"wwwroot/vendor/scrollreveal/scrollreveal.min.js", "wwwroot/vendor/scrollreveal/scrollreveal.min.js",
"wwwroot/vendor/magnific-popup/jquery.magnific-popup.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);
});
});