In our database we have some tables that have fields of type "Date" with date only values like "2024-01-24". The Microsoft documentation specifies that the equivalent .net framework type for a sql "Date" type is "DateTime", so when we defined our EntityFramework classes this table type, we used "DateTime" as the type for these fields. When we do a query like the following, the server is serializing the objects with the correct date, but the timezone is incorrectly set to local time of the server rather than being set to UTC and it causes the data returned to be off by one day.
public async Task<MyClass[]> GetMyClasses(MyDbContext myDbContext) => await myDbContext.MyClasses.ToArrayAsync();
So for example, if in the database the date was set to "2024-01-24", on a server set to zulu time, the datetime returned will be "2024-01-24T00:00:00Z", but on a local dev server that is set to the local time zone of Eastern US, the value is incorrectly set to "2024-01-24T00:00:00-4:00" which when converted to a UTC date in the client gives us a date of "2024-01-25" instead of "2024-01-24".
Is there something that we should be doing differently when we define our EntityFramework classes or HotChocolate GraphQL server?
To work around the issue, is it possible to use .AddTypeConverter<>() at startup time to specify code to properly convert to UTC for transfer over the network?
@huysentruitw Thank you very much. That worked. We updated to .Net 8 and changed the Data type in our entity classes from DateTime to DateOnly. When HotChocolate serializes a DateOnly, it comes across the network in the JSON as a date like "2024-01-24" and then on the client side (where we use Luxon in typescript) we're able to parse that into a date and treat it as UTC with the following code:
DateTime.fromISO(property).toUTC()
One thing that tripped us up for a little bit with the .Net 8 upgrade is that they changed the default port for containerized apps from port 80 to port 8080, so our deployments were broken for a bit until we realized that. That's not a hot chocolate or date related thing, but I just wanted to note that the upgrade to .Net 8 wasn't just a simple base container image change because I'm accepting an upgrade to .Net 8 as the best answer.
Thanks again for your help @huysentruitw