Some developers store all dates in the database as UTC. When materializing dates, it would be nice for DO to set their Kind property to Utc instead of Unspecified.

"Unspecified" causes a lot of unintended consequences. For example, if I have a JSON service that queries and returns some entities that have Date fields, then the .NET JavaScriptSerializer class will first convert my "already UTC" dates to UTC again. This is a very common use-case in ASP.NET MVC.

For example, let's say that the date January 1, 1970 midnight UTC (Unix epoch) is stored in a database. When DO materializes this date as part of an entity, it materializes the DateTime instance with DateTimeKind.Unspecified.

When JavaScriptSerializer serializes it into JSON, it first converts it to UTC, thinking that it represents local time. So, if my server is in New York, it will be converted to 5AM, which is wrong.

For now, I am materializing dates using DateTime.SpecifyKind(myEntity.Date, DateTimeKind.Utc).

It would be nice to be able to remove all such repetitive statements from my code.

asked Feb 27 '12 at 21:09

ara's gravatar image


One Answer:

Hello Ara,

Support of DateTimeOffset is planned in one of the future versions of DO.Net. Will that satisfy your requirements and make your life a bit more relaxed?

answered Feb 28 '12 at 03:16

Dmitri%20Maximov's gravatar image

Dmitri Maximov

Your answer
Please start posting your answer anonymously - your answer will be saved within the current session and published after you log in or create a new account. Please try to give a substantial answer, for discussions, please use comments and please do remember to vote (after you log in)!
toggle preview


Once you sign in you will be able to subscribe for any updates here



Asked: Feb 27 '12 at 21:09

Seen: 93,748 times

Last updated: Feb 28 '12 at 03:16

powered by OSQA