DateTime returned is off by -1 day
Hi, I found another issue with handling dates. I have a class that contains a field of type Date and of course I need to write and read this value, but the written and read values do not match. Here is some sample code:
using (var db = new Database("mydbpool")
{
var doc = new ODocument { OClassName = "myClass" };
doc.SetField<DateTime>("Date", new DateTime(2015, 02, 08));
var retval = db.Insert(doc).Run();
var readDate = retval.GetField<DateTime>("Date");
}
You would expect that readDate matches "new DateTime(2015, 02, 08)", but it comes out 2015/02/07. The value of 2015/02/08 is stored to the Database correctly. During the process of reading the date the value gets altered.
I am using the document model here.
[UPDATE1] The actual value returned in the ODocument is only off by -1 hour. Of course when you are only looking at the date, you are off by -1 day. So somewhere this hour gets lost. Perhaps again some issue with the Java -> .Net conversion?
[UPDATE2] I figured that it might be related to some UTC conversion issues, since I am located in Germany and my system is UTC+1. So I set my system to GMT/UTC time zone and to UK regional settings. But the offset still persists.
The following NUnit snippet works on my machine.
database.Create.Class("myClass").Run();
var doc = new ODocument { OClassName = "myClass" };
var date = new DateTime(2015, 02, 08);
doc.SetField<DateTime>("Date", date);
var retval = database.Insert(doc).Run();
var readDate = retval.GetField<DateTime>("Date");
Assert.That(readDate, Is.EqualTo(date));
I am able to reproduce it in a test case in my latest PR. The date is correct in the database but when it is retrieved it is moved forward by UTC - local time zone. I'm in PST and therefore it is adding 8 hours to the time that is stored in the database.
Related to issue #31
@bnoffer You should be able to work around this problem by executing
ALTER DATABASE TIMEZONE UTC