Open ghost opened 6 years ago
Agree with @insertnamehere, according to MS docs DateTimeStyles.AssumeUniversal
has the following description
If no time zone is specified in the parsed string, the string is assumed to denote a UTC.
which means, it must not convert to UTC, but just specify the UTC kind. Also IsoDateTimeConverter
doesn't support DateTimeStyles.AssumeLocal
So, behavior must be following
DateTimeStyles.AdjustToUniversal: Convert DateTime to UTC.
DateTimeStyles.AssumeUniversal: Specify UTC kind.
DateTimeStyles.AssumeLocal: Specify Local kind.
Any updates on this?
Why is this still not fixed? It's easy to fix, and it's a serious bug that can lead to subtle data integrity issues.
Source/destination types
Source/destination JSON
Expected behavior
When using IsoDateTimeConverter with DateTimeStyles = DateTimeStyles.AssumeUtc, it is expected that the DateTime will not be converted to UTC time when serializing to a JSON string
Actual behavior
InsertTsUtc was converted to UTC before formatting and serializing to a JSON string
Notes
In my case, InsertTsUtc comes from MSSQL Database and the column type is DateTime2. It is populated by a default constraint of GETUTCDATE().
When it is retrieved from the database, InsertTsUtc.Kind is DateTimeKind.Unspecified and the value is the correct UTC time that was generated by the default constraint.
I believe the issue may be in the IsoDateTimeConverter.WriteJson method
The conditional statement on line 85 (and 96)
Should probably be
Steps to reproduce