Version 0.9: Enketo reports "invalid date" for a calculated date working in Collect

Following suggestion of @lognaturel, I have closed the issue on github and repost it here.

I have a text field which is filled in calculation by: format-date-time(once(now()), '%H:%M:%S

This works fine in ODK Collect, giving date in German Format ( 20.07.2020).

In Enketo Preview (version as of today), and "invalid date" is displayed - other fields are ok at first sight.


I think Format date time not working in Enketo might be the same issue. There's possibly a workaround in that thread. I don't see any issues with the call but perhaps @martijnr (Enketo's creator) will see something I don't.

1 Like

Thanks! It can be tracked here:

1 Like

I finally looked at this, and I think 'Invalid Date' actually makes sense because of where the once function is placed. It should be once(format-date-time(now(), '%H:%M:%S')) instead*.

The once function returns the value of the question if it is not empty. What is happening is the calculation itself is run more than once (which can always happen - no guarantees for how many times a calculation is re-calculated). After the first time it's trying to convert a time format (the current value such as "15:32:01"), which is not a valid dateTime.

So Collect is either smart enough to really only run the calculation once, or its implementation of format-date-time is more permissible than our spec: ODK XForms Specification by also accepting a time format parameter.

Unless my analysis is incorrect, Enketo won't make any changes, since it behaves correctly.

* not relevant to the bug report but nowadays you'd want to avoid using once() altogether by using a default instead

1 Like

Ah, yes, indeed. Collect will not re-evaluate the expression within a form edit session but it will attempt to do so if the form is opened again. Then Collect will give the same type error.

1 Like