Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New serializers are sensitive to locale #2612

Closed
ewoutkramer opened this issue Oct 26, 2023 · 0 comments · Fixed by #2613
Closed

New serializers are sensitive to locale #2612

ewoutkramer opened this issue Oct 26, 2023 · 0 comments · Fixed by #2613

Comments

@ewoutkramer
Copy link
Member

ewoutkramer commented Oct 26, 2023

Torben Hagensen reported on Zulip (https://chat.fhir.org/#narrow/stream/179171-dotnet/topic/Serializing.20instant.20elements) that the new serializers are formatting the Instant type incorrectly, and indeed it is easy to reproduce that our serialization logic is sensitive to locale:

CultureInfo.CurrentCulture = new CultureInfo("da");

string FMT_FULL = "yyyy-MM-dd'T'HH:mm:ss.FFFFFFFK";
var now = DateTimeOffset.Now;

// Returns 2023-10-26T13.27.49.0572969+02:00
now.ToString(FMT_FULL).Dump();

// Returns 2023-10-26T13:27:49.0572969+02:00
XmlConvert.ToString(now,FMT_FULL).Dump();

It turns out that in the case of DateTimeOffset.ToString(), we run into localization issues, even though we fully specify the output format. This behaviour is different from the XmlConvert.ToString(), which we have used before.

The solution is to explicitly tag the invariant culture along:

// Returns 2023-10-26T13:27:49.0572969+02:00
now.ToString(FMT_FULL, CultureInfo.InvariantCulture).Dump();

I am pretty sure this logic is present in other parts of the new System types, and newer serializers so we should ensure we look a bit further than just the serializers.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant