Skip to content

Commit

Permalink
Fix issue with parsing date with hardcoded format
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
snowfrogdev committed Oct 5, 2022
1 parent 4c9ae69 commit fb8980c
Showing 1 changed file with 1 addition and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public async Task<DateTime> 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;
}
Expand Down

0 comments on commit fb8980c

Please sign in to comment.