-
Notifications
You must be signed in to change notification settings - Fork 4.9k
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
Add (Try)GetDateTime(Offset) to Utf8JsonReader and JsonDocument #28459
Comments
Things to think about:
|
Customer here, may I request it? |
Apparently long is still fairly popular, besides ISO8061. |
I don't think methods for Guid are that important. If Guid then why not TimeSpan, Uri, Version, etc. DateTime/DateTimeOffset are more common, and also I think it is worth offering an opinion about how they are written and read. Dates are a pain point in JSON and an obvious choice stops everyone going out and doing there own thing.
There is no way to know if an integer is ticks, or seconds since unix epoch. |
Guid and Timespan are imho better choices, as we already have Utf8Parser/Formatter support. Neither Uri, nor Version have that afaik and need to go through string. Timespan is as weird as datetime regarding formatting, even with ISO 8601 support, e.g. P1Y2M10DT2H30M (which I don't think many use). I agree about |
Looks good. We should consider applying the same principle from the writer to the reader: the writer differentiates between the underlying primitive and the convenience conversion (e.g. |
To start with, the (Try)GetDateTime(Offset) methods will by default parse input strings according to ISO 8061, but ignore CultureInfo and timezone conversion mechanisms. This means the output DateTime(Offset)’s timezone and kind will be the same as the input, if provided. If the millisecond portion of the input string is provided, fraction digits will be truncated beyond 7 decimal places. There is an internal |
Add (Try)GetDateTime(Offset) to Utf8JsonReader This change partially addresses https://github.com/dotnet/corefx/issues/34690. These methods parse JSON strings to DateTime(Offset) objects according to format `YYYY-MM-DD[Thh:mm[:ss[.s]][TZD]]`
* Add (Try)GetGuid to Utf8JsonReader This partially addresses https://github.com/dotnet/corefx/issues/34690. * Address review feedback * Address memory-related comments * Address more review comments * Re-add length check for span to be parsed * Reduce code duplication
(Try)GetDateTime(Offset) and (Try)GetGuid methods have been added to Utf8JsonReader and JsonElement. |
We should be consistent regarding what .NET types the
Utf8JsonReader
,Utf8JsonWriter
, andJsonDocument
support.Since there is strong need for adding DateTime support (and the writer allows users to write one), we should add the following APIs to the reader and document.
Add:
For consistency, we should remove Write(Guid) from the writer unless a customer requests it. If we want to keep Guid support, add it to the reader/document as well.
Remove:
cc @bartonjs, @steveharter, @JamesNK
The text was updated successfully, but these errors were encountered: