Nucleus .Net Core CMS

DateTimeUtcConverter Class

Namespace: Nucleus.Data.EntityFramework
Assembly: Nucleus.Data.EntityFramework.dll
The Entity Framework implementation for some database types do not store time zone information / set the DateTime.Kind to Unspecified. This causes problems when converting values to "Local". This converter ensures that date/time values are converted to UTC when they are saved to the database, and that when Date/time values are read from the database, the .Kind property is set to Utc.
ConvertFrom (DateTime value)
Convert a value after reading it from the database
Parameters
Name Type
value DateTime
Returns
This function sets the "Kind" property to Utc without changing the value of the date/time, unless the value is DateTime.MinValue. If the value is DateTime.MinValue, the value is returned as-is.
ConvertTo (DateTime value)
Convert a value before writing it to the database.
Parameters
Name Type
value DateTime
Returns
This function keeps a datetime with a value of DateTime.MinValue as-is, but converts all other values to UTC. If the value is already UTC, .ToUniversalTime will not change it. https://github.com/dotnet/runtime/blob/main/src/libraries/System.Private.CoreLib/src/System/TimeZoneInfo.cs#L824