diff --git a/lib/ui/locations/entries/date.mjs b/lib/ui/locations/entries/date.mjs index db7c629cb..5d9f619ec 100644 --- a/lib/ui/locations/entries/date.mjs +++ b/lib/ui/locations/entries/date.mjs @@ -1,32 +1,41 @@ export default entry => { - let val + const dateString = new Date(entry.newValue || entry.value * 1000) + .toLocaleDateString(entry.locale, entry.options); // day only as configured in workspace + + const timeString = new Date(entry.newValue || entry.value * 1000) + .toLocaleTimeString([], { hour: '2-digit', minute: '2-digit' }); // time only as 00:00 if (entry.edit) { - val = mapp.utils.html.node` + // formatted value for input element. + const formats = { + datetime: `${new Date(entry.newValue || entry.value * 1000).toLocaleDateString("fr-CA")}T${timeString}`, // YYYY-MM-DDT00:00 + date: `${new Date(entry.newValue || entry.value * 1000).toLocaleDateString("fr-CA")}` // YYYY-MM-DD + } + + // return date/time input + return mapp.utils.html.node` { - entry.newValue = new Date(e.target.value).getTime() / 1000 + entry.newValue = new Date(e.target.value).getTime() / 1000; - entry.location.view?.dispatchEvent( - new CustomEvent('valChange', { - detail: entry - }) - ) + entry.location.view?.dispatchEvent( + new CustomEvent('valChange', { + detail: entry + })) + }}>`; - }}>`; - - } else { - - val = entry.value && new Date(entry.value * 1000).toLocaleString(entry.locale, entry.options) } + // Assign val for non-editable entry. + const val = entry.value + && (entry.type === 'datetime' ? `${dateString} ${timeString}` : dateString) + || 'null' + const node = mapp.utils.html.node`