diff --git a/Lieb/Data/TimeZoneService.cs b/Lieb/Data/TimeZoneService.cs index 0def12b..1344b84 100644 --- a/Lieb/Data/TimeZoneService.cs +++ b/Lieb/Data/TimeZoneService.cs @@ -6,9 +6,6 @@ namespace Lieb.Data { private readonly IJSRuntime _jsRuntime; - private TimeSpan? _userOffset; - private int _offsetInMinutes; - public TimeZoneService(IJSRuntime jsRuntime) { _jsRuntime = jsRuntime; @@ -16,24 +13,18 @@ namespace Lieb.Data public async ValueTask GetLocalDateTime(DateTimeOffset dateTime) { - if (_userOffset == null) - { - _offsetInMinutes = await _jsRuntime.InvokeAsync("GetTimezoneValue"); - _userOffset = TimeSpan.FromMinutes(-_offsetInMinutes); - } + int offsetInMinutes = await _jsRuntime.InvokeAsync("GetTimezoneValue", dateTime); + TimeSpan userOffset = TimeSpan.FromMinutes(-offsetInMinutes); - return dateTime.ToOffset(_userOffset.Value); + return dateTime.ToOffset(userOffset); } public async ValueTask GetUTCDateTime(DateTimeOffset dateTime) { - if (_userOffset == null) - { - _offsetInMinutes = await _jsRuntime.InvokeAsync("GetTimezoneValue"); - _userOffset = TimeSpan.FromMinutes(-_offsetInMinutes); - } + int offsetInMinutes = await _jsRuntime.InvokeAsync("GetTimezoneValue", dateTime); + TimeSpan userOffset = TimeSpan.FromMinutes(-offsetInMinutes); - return new DateTimeOffset(dateTime.DateTime.AddMinutes(_offsetInMinutes), new TimeSpan(0)); + return new DateTimeOffset(dateTime.DateTime.AddMinutes(offsetInMinutes), new TimeSpan(0)); } public async ValueTask GetUserTimeZone() diff --git a/Lieb/Pages/_Host.cshtml b/Lieb/Pages/_Host.cshtml index cf6953e..bfe1a25 100644 --- a/Lieb/Pages/_Host.cshtml +++ b/Lieb/Pages/_Host.cshtml @@ -8,9 +8,10 @@ @(await Html.RenderComponentAsync(RenderMode.Server))