-
Notifications
You must be signed in to change notification settings - Fork 3.3k
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
Json.Net is modifying dates with explicit offsets #865
Comments
Use the DateParseHandling.DateTimeOffset setting |
Agreed with @oliverjanik. This behaviour just caught me out big time. It is not type safe and breaks the principle of least surprise. If a field contains a DateTime then it will be typed as a DateTime. Not a String. If my String field contains what looks like a DateTime then, by default, it should not be manipulated at all. |
I'm with @nbevans and @oliverjanik in part. If the framework is going to be smart about date time parsing then you need to be completely consistent in handling dates. In the case of the offset dates, you are violating the data contract implicitly by forcing an offset date into a date time. It should be left up to the caller to decide whether or not they convert to date time or keep it as an offset. The conversion can be handled gracefully both ways if the source is represented correctly, but not when its converted without the knowledge of the caller. |
@jetuser It's just a library, not a framework. If it were a framework then this behaviour MIGHT be acceptable. |
Use the DateParseHandling.DateTimeOffset setting. |
If a json property has a date specified with an offset, json.net appears to be affecting the actual time without changing the offset. This seems like a bug as if an offset is obviously part of a date string you should respect the time zone or adjust the offset approprioately:
"EndDate": "2016-03-31T12:00:55.2831445-07:00",
When casted to DateTimeOffset turns into:
endDate {3/31/2016 10:00:55 AM -07:00}
Edit: even if this is intentional by date settings, it is somewhat misleading as one would expect offsets are handled automatically by json.net if they are explicit
The text was updated successfully, but these errors were encountered: