we have an api that works with .net core 3.1, I just upgraded to 5.0 and the date behavior has changed.
i'm having a timezone problem.
Thanks for your comments.
Default behaviour (3.1)
Parameters:
createdOnGreaterThan: 2021-09-16T07:00:00.000Z
createdOnLessThan: 2021-09-16T08:00:00.000Z
Api Reads as:
createdOnGreaterThan: 2021-09-16 10:00:00 ( 3 added)
createdOnLessThan: 2021-09-16 11:00:00 ( 3 added)
After upgraded (5.0)
Parameters:
createdOnGreaterThan: 2021-09-16T07:00:00.000Z
createdOnLessThan: 2021-09-16T08:00:00.000Z
Api 5.0 Reads as:
createdOnGreaterThan: 2021-09-16 7:00:00 (no added)
createdOnLessThan: 2021-09-16 8:00:00 (no added)
CodePudding user response:
That default behaviour in .NET Core 3.1 was actually a bug where the model binder converts the UTC time from a query to a local DateTime
, when it should be UTC time see this issue.
The behaviour you are getting in .NET 5.0 is the correct behaviour, following the bugfix where it is left as the UTC time.
Unfortunately the bugfix is not critical and as such was not also applied to .NET 3.1.
Welcome to the world of Core over Framework, where once even the behaviour of bugs that we 'expected' remained for eternity :)