Display dates/times in local TZ (#7)
This commit is contained in:
30
src/JobsJobsJobs/Client/Shared/FullDateTime.razor.cs
Normal file
30
src/JobsJobsJobs/Client/Shared/FullDateTime.razor.cs
Normal file
@@ -0,0 +1,30 @@
|
||||
using Microsoft.AspNetCore.Components;
|
||||
using NodaTime;
|
||||
using NodaTime.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace JobsJobsJobs.Client.Shared
|
||||
{
|
||||
public partial class FullDateTime : ComponentBase
|
||||
{
|
||||
/// <summary>
|
||||
/// The pattern with which dates will be formatted
|
||||
/// </summary>
|
||||
private static readonly ZonedDateTimePattern Pattern =
|
||||
ZonedDateTimePattern.CreateWithCurrentCulture("ld<D> ' at ' lt<t>", DateTimeZoneProviders.Tzdb);
|
||||
|
||||
/// <summary>
|
||||
/// The date to be formatted
|
||||
/// </summary>
|
||||
[Parameter]
|
||||
public Instant TheDate { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The formatted date
|
||||
/// </summary>
|
||||
private string Translated { get; set; } = "";
|
||||
|
||||
protected override async Task OnInitializedAsync() =>
|
||||
Translated = Pattern.Format(TheDate.InZone(await state.GetTimeZone(js)));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user