Hi!
I’m making a form where I set field values after a promise is resolved, something like this:
$(input)
.val(value)
.trigger('change');
This value (rdt_session_time_started) can be a timestamp, like: 1628580917876
. The user can see but not modify this value.
- Is there a way to format a timestamp to a human readable text? For example:
Tue Aug 10 2021, 14:35:17
I’ve:
- tried
decimal-date-time(${rdt_session_time_started})
andformat-date-time(${rdt_session_time_started}, "%Y-%n-%e %H:%M:%S")
in thecalculation
, also by hardcoding the valuesdecimal-date-time(1628580917876)
but the result is wrong:NaN
. - checked openrosa-xpath-evaluator and I believe timestamp is probably not supported.
- created a
note
with a label calling acalculation
field outside the group like for having anotherpage
when clicking next. Etc…
But still wondering if anyone know an Eketo/XForm way.
In the meantime to unblock myself, I’ve created a function in to parse timestamps to Date objects in medic-xpath-extensions.
At the end it looks like this:
format-date-time(parseTimestampToDate(${rdt_session_time_started}), "%Y-%n-%e %H:%M:%S")
What happens is that parseTimestampToDate
runs only when loading the form and not when the value of the field changes, this field is either readonly or hidden because the user can’t modify the value.
- Not sure if this is because the field is readonly or hidden and the calculation doesn’t trigger because of that, or because the value is added after a promise resolved, or if I’m
parseTimestampToDate
in the wrong place. What do you think?
PD: The code and forms linked here are still in development and may contain experiments