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

Unclear description regarding equality of "K" and "zzz" time zone format specifier #43705

Open
MichaelRomer opened this issue Nov 22, 2024 · 0 comments
Labels

Comments

@MichaelRomer
Copy link

MichaelRomer commented Nov 22, 2024

Describe the issue or suggestion

The documentation states:

For DateTimeOffset values, the "K" format specifier is equivalent to the "zzz" format specifier [...]

while this may be the case for serialisation, this behaviour differs when deserializing time strings as shown in the example below.

const string inputWithOffset = "2023-08-31T07:00:00+02:00";
const string utcInput = "2023-08-31T07:00:00Z";
const string inputWithoutOffset = "2023-08-31T07:00:00";

DateTimeOffset.ParseExact(inputWithOffset, "yyyy'-'MM'-'dd'T'HH':'mm':'ssK", null, DateTimeStyles.None); //works
DateTimeOffset.ParseExact(utcInput, "yyyy'-'MM'-'dd'T'HH':'mm':'ssK", null, DateTimeStyles.None); //works
DateTimeOffset.ParseExact(inputWithoutOffset, "yyyy'-'MM'-'dd'T'HH':'mm':'ssK", null, DateTimeStyles.None); //works

DateTimeOffset.ParseExact(inputWithOffset, "yyyy'-'MM'-'dd'T'HH':'mm':'sszzz", null, DateTimeStyles.None); //works
DateTimeOffset.ParseExact(utcInput, "yyyy'-'MM'-'dd'T'HH':'mm':'sszzz", null, DateTimeStyles.None); //FormatException
DateTimeOffset.ParseExact(inputWithoutOffset, "yyyy'-'MM'-'dd'T'HH':'mm':'sszzz", null, DateTimeStyles.None); //FormatException

→ the "zzz" specifier does not allow the "Z" offset and a missing offset, while the "K" specifier accepts those.

I think this is worth to be mentioned in the documentation.

@dotnetrepoman dotnetrepoman bot added the ⌚ Not Triaged Not triaged label Nov 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant