DateTime? compare

17 views
Skip to first unread message

zdenek hostinsky

unread,
Sep 7, 2015, 7:37:04 AM9/7/15
to SharpKit Support
Hello

when comparing datetime, there is a problem with null value

sharpkit generates


for

if (equipment.EstimatedDeliveryTime == null)

sharkkit correctly generate 


 if (System.DateTime.op_Equality(equipment.EstimatedDeliveryTime, null)){


hovewer folloging throws an expception


Compare: function (t1, t2) {
return t1.valueOf() - t2.valueOf();
},

Z

Dan-el Khen

unread,
Sep 7, 2015, 8:20:54 AM9/7/15
to SharpKit Support
Can you tell me what exception it throws?

Thanks
D.

--
You received this message because you are subscribed to the Google Groups "SharpKit Support" group.
To unsubscribe from this group and stop receiving emails from it, send an email to sharpkit+u...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Zdenek Hostinsky

unread,
Sep 7, 2015, 8:22:22 AM9/7/15
to shar...@googlegroups.com

Hello

 

Null reference – as t2 is null

 

Zdenek

--
You received this message because you are subscribed to a topic in the Google Groups "SharpKit Support" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/sharpkit/N25En1vL23A/unsubscribe.
To unsubscribe from this group and all its topics, send an email to sharpkit+u...@googlegroups.com.

Dan-el Khen

unread,
Sep 7, 2015, 8:30:05 AM9/7/15
to shar...@googlegroups.com
I see, well, DateTime objects are never supposed to be null, can you reproduce this issue? I want to trace back how you got to that.

Thanks
D.

Zdenek Hostinsky

unread,
Sep 7, 2015, 8:33:06 AM9/7/15
to shar...@googlegroups.com

Simply by using DateTime?

 

Even using that

 

C# code like

 

if (equipment.EstimatedDeliveryTime == null)

is converted to comparion like

 

 if (System.DateTime.op_Equality(equipment.EstimatedDeliveryTime, null)){

 

 

 

simple workaround is to modify the C# code like

 

if (equipment.EstimatedDeliveryTime.HasValue == false)

 

 

so not a big issue – but probably worth fixing

 

(unless not fixed already, I’m on sharpkit 5.4.4)

 

Z

Dan-el Khen

unread,
Sep 7, 2015, 8:34:30 AM9/7/15
to shar...@googlegroups.com
But if EstimatedDeliveryTime is a struct, you're not supposed to be able to compare it with null.

D.

Zdenek Hostinsky

unread,
Sep 7, 2015, 8:35:24 AM9/7/15
to shar...@googlegroups.com

If it is DateTime? ( nullable type) I can really do that J

Dan-el Khen

unread,
Sep 7, 2015, 8:39:16 AM9/7/15
to shar...@googlegroups.com
So it's a Nullable<DateTime> and not a datetime, and that explains it much more. I'm not sure if DateTime equality should be called in this case so I'm kind of surprised here.

Basically you're saying that:

DateTime? x = null;
var b = x == null;

Will cause DateTime.op_Equality(x, null) ?

I'll happily check this, can you just verify that this is the case please?

Thanks
D.




Zdenek Hostinsky

unread,
Sep 7, 2015, 9:18:38 AM9/7/15
to shar...@googlegroups.com

Yes – talking about “datetime?” ( or Nullable<DateTime> - whatvever version you prefer)

 

And what you are describing is exactly the case

 

 

Thanks

Dan-el Khen

unread,
Sep 7, 2015, 9:39:46 AM9/7/15
to shar...@googlegroups.com
You're right, verified. It seems that DateTime equality methods are called instead of Nullable.Equals and compare is called (or implemented). Firstly, I need to check if this is caused by the parser or sharpkit.
Anyway, added:

Thanks for detecting and reporting this!

Cheers
D.

Reply all
Reply to author
Forward
0 new messages