The current(July) preview of RIA Services handles DateTime objects in an strange manner. Many of silverlight developers have complained in Silverlight forums that their dates are messed up. In this post, I am listing down several observations as a reference. Note that my current settings are +6 GMT.
From DateTime.Kind DateTime.Value To DateTime.Kind DateTime.Value ---- ------------- ---------------- -- ------------- --------------- Client Unspecified 2009-01-01 00:00 Server Utc 2008-12-31 18:00 Server Unspecified 2009-01-01 00:00 Client Utc 2008-12-31 18:00 Client Local 2009-01-01 00:00 Server Utc 2008-12-31 18:00 Server Local 2009-01-01 00:00 Client Utc 2008-12-31 18:00 Client Utc 2009-01-01 00:00 Server Utc 2009-01-01 00:00 Server Utc 2009-01-01 00:00 Client Utc 2009-01-01 00:00
We can see that whatever Datetime we send, RIA service converts it to UTC when received at the other end. This could be bearable up to some extent but the worst thing is that RIA domain service treats Unspecified dates as Local and performs respective time zone conversion. Also, there is a
UsesUtcDateTimes overridable in DomainService class but currently it does not seem to produce any effect.
Notice that there is no such conversion when using a WCF service, so whatever datetime value and kind we send from one side is exactlyreceived the same at the other side.
Lets hope the issues are fixed in the next version of RIA services.
My sample application that I used to test the behavior of RIA Domain Service and WCF Service can be downloaded from here. Remember to rename it to .zip for extraction.
August 28, 2009 at 4:20 PM
Hello Mehroz,
wow, I’m googling and struggling with this one a few hours now. The problem seems to be the RIA ignores UsesUtcDateTimes==true at all – it should effectively ignore any .Kind==unspecified etc., if one overrides the getter for UsesUtcDateTimes
..
No solution so far, I’ll try to override some RIA framework class to workaround this. And as funniest fallback: one adds 4 hours here in Switzerland
. Very nice solution.
Good luck,
Andrej
August 28, 2009 at 4:54 PM
Update: the UsesUtcDateTimes seems to convert the UTC server fetched DateTime because the .Kind==Unspecified. But – how to enforce .Kind=Utc in the Entity Framework, that’s the question..
Any ideas? W/out having to write strange partial class helpers etc..
Thanks, Andrej
September 4, 2009 at 9:02 AM
Hi Andrej,
To enforce DateTime.Kind = Utc in Entity Framework, the easiest solution will be to extent the generated partial dataclasses and provide an implementation for your
OnDateColumnChanged()method to assign a Utc kind to the incoming date. Something like:this._dateColumn = DateTime.SpecifyKind(this._dateColumn, DateTimeKind.Utc);Once you tag your datetime objects with Utc kind as described above, you are going to receive the same DateTime value at your Silverlight client.
November 25, 2009 at 5:14 PM
[...] there’s a little known bug “feature” in the latest RIA Services Beta for Silverlight that involves [...]