Local and UTC Dates in NHibernate
How do you get a UTC datetime hydrated from NHibernate? Dan Morphis addressed this a while ago with an interceptor.
I proposed a patch to NHibernate that adds UtcDateTime and LocalDateTime data types that will specifically get hydrated with the proper DateTimeKind value instead of DateTimeKind.Unspecified.
Usage <property name="MyDate" type="UtcDateTime"></property> <property name="LocalDate" type="LocalDateTime"></property>
You download the patch from Jira, and vote for it if you like it.
Adam, its good to know someone found my post useful!
I stumbled upon your blog post and the bug tracker entry while searching on this issue. After all, I guess the idea solution of using a custom data type is better than Dan’s interceptor, because it should use less resources. Anyways, it would be nice if the type also checked that the given
DateTimeobject if ofDateTimeKind.UTCor converts it to that. Of course, this behaviour would need documentation, but using solely your solution would allow someone to fill the DB withDateTimeKind.LocalorDateTimeKind.Unspecifieddates without problem, thus giving really weird dates if those were read from the database (asDateTimeKind.UTC, using your patch) and then converted to a local time in order to be displayed to a client or on a website.@hangy… That is why applications should be running unit and integration tests.