From 3c10c8d119df4f3b85a6f4d47e8e1f2a2aa4b01b Mon Sep 17 00:00:00 2001 From: Agata Brok Date: Fri, 10 Nov 2023 14:35:52 +0100 Subject: [PATCH] Locations/entries/date - now takes user time zone; Resolved problem of displayed value, unix epochs and formatting for the input of type date. --- lib/ui/locations/entries/date.mjs | 32 +++++++++++++++++++++++-------- 1 file changed, 24 insertions(+), 8 deletions(-) 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`