Format UTC offsets with the invariant culture - #1854
Merged
Conversation
GetDateOffset built the offset with plain interpolation, so the numbers went through CurrentCulture while every other part of the rendered date passed Culture.InvariantCulture explicitly. NumberFormatInfo.NegativeSign is not "-" everywhere. sv-SE renders U+2212 MINUS SIGN, ar-SA prefixes U+061C ARABIC LETTER MARK, and fa-IR uses U+200E + U+2212. Only negative offsets are affected, since the positive and zero branches write a literal "+". The string reaches two places. As snapshot content, via Convert, a DateTimeOffset serialized on a Swedish machine differs from the one committed from an en-US machine even though the values are equal. As a parameter file name, via ToParameterString, the verified file for offset -05:00 is looked up under a name that machine can never produce a match for.
This was referenced Aug 17, 2026
This was referenced Aug 26, 2026
This was referenced Aug 27, 2026
Open
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
GetDateOffsetinsrc/Verify/Serialization/DateFormatter_DateTimeOffset.csbuilt the offset with plain interpolation, so the numbers went throughCurrentCulture, while every other part of the rendered date in that file passesCulture.InvariantCultureexplicitly.NumberFormatInfo.NegativeSignis not-everywhere:-01:30renders asU+002D-1-30U+2212−1−30U+061C U+002D-1-30U+200E U+2212−1−30Only negative offsets are affected; the positive and zero branches write a literal
+.Impact
The string reaches two places.
DateFormatter.Convert. ADateTimeOffsetserialized on a Swedish machine differs from the one committed from an en-US machine even though the values are equal.DateFormatter.ToParameterString. The verified file for a parameter with offset-05:00is looked up under a name that machine can never produce a match for, so the test reports the snapshot as new on every run.Change
The four interpolations now go through
FormattableString.Invariant, which keeps the format strings in place and is available on every target framework down to net462. Output under the invariant culture is byte identical, so no existing snapshot moves.Test
DateFormatterTests.OffsetDoesNotTakeTheCurrentCultureNegativeSignpins all five branches (-1.5,-5,+1.5,+5,0) against expected literals whileCurrentCulturecarriesU+2212as its negative sign. The sign is assigned onto a clone of the invariant culture rather than picking a real culture, so the assertion does not move with the ICU data the test runs against.Confirmed the test fails on unpatched source (both negative cases, positives unaffected) and passes after. Full
Verify.Testssuite green: 1304 passed, 0 failed.Verify.csprojbuilds clean across all nine target frameworks.