From fb8980ce41deecf76c6f06203be6dffce2e141bb Mon Sep 17 00:00:00 2001 From: Philippe Vaillancourt Date: Wed, 5 Oct 2022 12:57:31 -0400 Subject: [PATCH] Fix issue with parsing date with hardcoded format We are creating a DateTimeOffset on the server and sending it in string format to the client. There, using ParseExact and a hardcoded US date format, we are converting it back to a DateTimeOffset. The problem is that when the date is created on a server that is in a non-US locale, the client throws and error and the app crashes. --- FrontDesk/src/FrontDesk.Blazor/Services/ConfigurationService.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/FrontDesk/src/FrontDesk.Blazor/Services/ConfigurationService.cs b/FrontDesk/src/FrontDesk.Blazor/Services/ConfigurationService.cs index 3d2f7e8..a95142d 100644 --- a/FrontDesk/src/FrontDesk.Blazor/Services/ConfigurationService.cs +++ b/FrontDesk/src/FrontDesk.Blazor/Services/ConfigurationService.cs @@ -21,7 +21,7 @@ public async Task ReadAsync() _logger.LogInformation("Read today date/time from configuration."); var stringDateTimeOffset = await _httpService.HttpGetAsync($"api/configurations"); - var dateTimeWithOffset = DateTimeOffset.ParseExact(stringDateTimeOffset, "MM/dd/yyyy HH:mm:ss zzz", CultureInfo.InvariantCulture); + var dateTimeWithOffset = DateTimeOffset.Parse(stringDateTimeOffset, CultureInfo.InvariantCulture); return dateTimeWithOffset.UtcDateTime; }