diff --git a/lib/ui/locations/entries/date.mjs b/lib/ui/locations/entries/date.mjs index db7c629cb..5f73f5ca5 100644 --- a/lib/ui/locations/entries/date.mjs +++ b/lib/ui/locations/entries/date.mjs @@ -1,18 +1,33 @@ export default entry => { - let val + let val; + + let d = new Date(entry.value * 1000) + .toLocaleDateString(entry.locale, entry.options); // day only as configured in workspace + + let t = new Date(entry.value * 1000) + .toLocaleTimeString([], {hour: '2-digit', minute:'2-digit'}); // time only as 00:00 if (entry.edit) { + // these formats are only needed to pass values formatted for the input element + const formats = { + datetime: `${new Date(entry.value * 1000).toLocaleDateString("fr-CA")}T${t}`, // YYYY-MM-DDT00:00 + date: `${new Date(entry.value * 1000).toLocaleDateString("fr-CA")}` // YYYY-MM-DD + } + val = mapp.utils.html.node` { - entry.newValue = new Date(e.target.value).getTime() / 1000 + // this gets user timezone + //let timezone = Intl.DateTimeFormat().resolvedOptions().timeZone; + + let unix = new Date(e.target.value).getTime() / 1000; + + entry.newValue = unix; entry.location.view?.dispatchEvent( new CustomEvent('valChange', { @@ -22,9 +37,10 @@ export default entry => { }}>`; - } else { + } + else { - val = entry.value && new Date(entry.value * 1000).toLocaleString(entry.locale, entry.options) + val = entry.value && entry.type === 'datetime' ? `${d} ${t}` : `${d}`; } const node = mapp.utils.html.node`