Little problem with date comparison (JS and CLR)

Aug 11, 2011 at 4:39 PM

Hello to everyone :)

I'm here again to show a little problem i encountered in date comparison.
This is the code i execute: 

var a = new System.DateTime(2011,8,11,16,1,1);
var b = new Date(2011,7,11,16,1,1);

return a == b;

If you execute it with Jint (0.9.0) it returns false (version 0.8 of jint execute it correctly and return true).

The two dates differ in the values of hour (one is 16 o'clock the other is 17....)

If it can help, i noticed this situation in ExecutionVisitor.cs (on line 775):

if (x.IsClr)
      return Compare(x.ToPrimitive(Global), y);

until this point x and y are identical. 
On second execution of Compare method (when both date are no more Clr), at line 824

return Global.BooleanClass.New(x == y);

x is one hour ahead.

I'll try to go deeper in the code to find out more about it.

Thanks in advance, see soon :)

Aug 11, 2011 at 5:01 PM

Would be interesting to see how time zones are affected here. This might be the issue. Like the Date is using UTC by default, and DateTime is using local. And if it happens you are close from Greenwitch, this might explain.

Aug 12, 2011 at 11:14 AM

Thanks for reply Sebastien.

Yes I'm in GMT+1

I tried using this construct:

val = new DateTime(2010,11,17,19,01,01, DateTimeKind.Utc);

but it behaves in same way.

Value of x and y (the two dates) are the same, for now i just changed my script in

return a.Value == b.Value;

Strange thing is that jint 0.8 don't have this problem.  

I did some other tests, and found another strange situation:

var dd = new Date(2010, 10, 17, 19, 01, 01);
return dd.getMilliseconds();

If you execute above code, it will return 121 
Any setting will always return 2 milliseconds before.

Hoping to be usefull, i'll continue my studies :)

Aug 12, 2011 at 3:14 PM

You can open bugs for that, I'll mark them fixed when I have pushed more unit tests and fixes.