Updated the IsoDateTimeConverter initialization in the JsonDateTimeFormatAttribute to set the Culture to InvariantCulture so that the custom DateTime format symbols ( date and time separators) are respected independent of the CurrentCulture being used.

This commit is contained in:
miguelcrpinto
2023-06-17 10:28:53 +02:00
committed by Zeegaan
parent 5c5de77965
commit 7e573c70a3

View File

@@ -1,4 +1,5 @@
using System.Buffers;
using System.Globalization;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.Filters;
using Microsoft.Extensions.Options;
@@ -42,7 +43,7 @@ public sealed class JsonDateTimeFormatAttribute : TypeFilterAttribute
{
var serializerSettings = new JsonSerializerSettings();
serializerSettings.Converters.Add(
new IsoDateTimeConverter { DateTimeFormat = _format });
new IsoDateTimeConverter { DateTimeFormat = _format, Culture = CultureInfo.InvariantCulture });
objectResult.Formatters.Clear();
objectResult.Formatters.Add(
new AngularJsonMediaTypeFormatter(serializerSettings, _arrayPool, _options));