DateTime type has an enum property called 'DateTimeKind', which can be set as one of these: 'Local', 'Unspecified' and 'Utc'.
When the value gets queried from database with 'datetime' format, if it is being queried using Dapper, this DateTimeKind is 'Unspecified' and then automatically calculate the time to local time as being instantiated inside 'DateTimeOffset' object.
Current back-end standard is Utc and I would like to create a property handling this 'DateTimeKind' value default to 'Utc' as that is what to be expected.
And not only that, I would like to create some helper function auto-convert datetime value as well as setting specifyKind to 'Utc' if it was fed as different kind.
One simple thought into it is handling in setter something like:
private DateTime? _someValue;
[DataMember]
public DateTime? SomeValue
{
get
{
return _someValue;
}
set
{
if (value.HasValue)
{
//Todo: do something more such as converting datetime value as well if DateTimeKind was not Utc as coming in..
_someValue = DateTime.SpecifyKind(value.Value, DateTimeKind.Utc);
}
}
}
Please let me know if there is known way not to reinvent wheels.