tl;dr When comparing for equality in javascript, it checks whether objects are the same, and not whether the value is the same. So for objects, one need to convert them into a number, like with dv.date(today).ts
.
This is related to how javascript functions, and when you compare two dates you’re comparing two objects. And when checking for equality between objects, they’ve got to be the same object. See Equality (==) - JavaScript | MDN .
Therefore whenever you need to compare two dates for equality, you need to transform them into a number, and a very easy way to do this is in our environment is to the dv.date('today').ts
. Here is an image showing a note describing a completion date (similar to the due date, but easier for me to produce ) and the
dv.date(today)
.
As can be seen, the base comparison would be between two objects, with the class name “DateTime”, but they are not the same object in memory, and as such an equality operation would fail.
Finally, the reason t.due == dv.date(today).ts
actually works, is that javascript sees the two values as two different types, and tries to make them comparable. So when dv.date(today).ts
is seen as a number, it tries to convert t.due
, which is perfectly capable of presenting itself as a number, which happens to be the .ts
value.