Issue with date comparison in Collect

Last week I faced one difference. I wanted to constraint an "end" date time to be greater than the "start" one.

This works fine in enketo but don't in collect (constraint column for the end_date):

. > ${start_date}

But I needed to transform it for Collect as :

decimal-date-time(.) > decimal-date-time(${start_date})

Hi, how did you set/enter the two dates, please? Would you mind to share a short extract/example in XLSForm?

Thanks @wroos !
In Collect, the constraint (. > ${date_time_debut} )always throw an error.
I am very surprised to face it so I hope the bug is not in my brain...


date_time_comparison.xlsx (741,9 Ko)

Hi @mathieubossaert,
could you try with dateTime spelling as type, please?
(See https://getodk.github.io/xforms-spec/#data-type:dateTime and https://docs.getodk.org/form-question-types/#datetime-widget).
But I am afraid, this will not solve the problem, as your screenshot shows a dateTime widget.

The > operator should work here, as the spec says

Note that the standard XPath type conversions are extended by this specification in the number() function. This extended functionality provides the ability to perform arithmetic with, and compare, date and dateTime strings.
(https://getodk.github.io/xforms-spec/#xpath-operators)

But maybe the number() conversion only covers the day part? You might test it with a manually coded cast, like number(.) and show the result and test number(.) > number( ${date_time_debut} ). It would be interesting how the time part is treated in Collect (and differently in Enketo).

Same error on Collect

Dear @mathieubossaert,
I did some further tests, with the following extended example.
date_time_comparison02.xlsx (900.0 KB)

There seems to be a problem in Collect (or at least strange behaviour).
ODK Collect (I tested with v2024.3.0 Beta 8)


Different to Enketo (tested with https://getodk.org/xlsform/)

In Collect: number() function and also $-reference in label for dateTime variable seem incomplete. Only if the date part is different, it works as expected.

Hint: date time or datetime (spelling) is automatically converted to type="dateTime" in XML file.

Hint @LN: Type in spec is dateTime, but datetime in ODK template? Same spelling would be better?

1 Like

I agree it looks like there are some issues in this area. We'll try to triage soon.

2 Likes