I just got bitten by a surprising behavior when trying to write some bindings for luxon.
if dt1 > dt2 {
stuff
} else {
otherStuff
}
This was compiling to
if (Caml_obj.caml_greaterthan(dt1, dt2)) {
return stuff
} else {
return otherStuff
}
I looked at the implementation of caml_greaterthan and it was giving incorrect comparisons. The thing is that luxon DateTime’s implement valueOf: t => float
. This is common in the JS ecosystem to enable comparison operators to work smoothly. I’m wondering if the caml_greaterthan function should make use of it? What do you think?
In the meantime I’ve worked around it by using undocumented extension points
external isBefore: (t, t) => bool = "%ltint"
external isAfter: (t, t) => bool = "%gtint"
external isSameOrBefore: (t, t) => bool = "%leint"
external isSameOrAfter: (t, t) => bool = "%geint"