Timezones and importing DateTime fields using ReadXML

Posts   
 
    
colinvella
User
Posts: 12
Joined: 28-Feb-2006
# Posted on: 19-May-2006 11:56:19   

I just wanted to highlight an issue my team experienced while implementing an import / export function. We basically implemented the functionality using the entity object's ReadXML and WriteXML methods, with some entity flags changed to force inserts or updates accordingly.

We experienced a problem when importing entities with DateTime properties set to DateTime.MaxValue. On deserialising the DateTime objects, the time is shifted according to the local time zone. If the required timeshift is positive, this causes the date value to exceed maximum date range and deserialisation fails.

We solved this by storing all MaxValue dates as DateTime.MaxValue.AddDays(-1). This gives the timezone shift calculation some leeway without exceeding the absolute maximum. The problem manifested itself only when exporting from a timezone that is 'behind' the timezone of the destination.

I don't know if this issue should be classified as an LLBLGEN bug, DotNet bug or simply a 'feature', but I'd thought I'd offer a solution for those stuck with a similar problem simple_smile

I hope you find this little anecdote helpful. Regards

Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
pilotboba
User
Posts: 434
Joined: 05-Aug-2005
# Posted on: 19-May-2006 16:20:22   

colinvella wrote:

I don't know if this issue should be classified as an LLBLGEN bug, DotNet bug or simply a 'feature', but I'd thought I'd offer a solution for those stuck with a similar problem simple_smile

Yes... I read and article on using DateTime that said if you do any date time work you should store UTC and local time is only used to display to/prompt from the user. I think if you did this and you were passing UTC it would eliminate this problem.

http://msdn.microsoft.com/netframework/default.aspx?pull=/library/en-us/dndotnet/html/datetimecode.asp

BOb

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39928
Joined: 17-Aug-2003
# Posted on: 19-May-2006 21:21:45   

You can make LLBLGenPro use the xml datetime format simple_smile Use the WriteXml overload which accepts an XmlFormatAspect parameter. You can then specify if you want DatesInXmlDataType simple_smile

Frans Bouma | Lead developer LLBLGen Pro