From 3c10c8d119df4f3b85a6f4d47e8e1f2a2aa4b01b Mon Sep 17 00:00:00 2001 From: Agata Brok Date: Fri, 10 Nov 2023 14:35:52 +0100 Subject: [PATCH 1/2] 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 db7c629cb5..5f73f5ca54 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` From 2330fe45387e7cc9f07556329538e3aa7f99c03a Mon Sep 17 00:00:00 2001 From: dbauszus-glx Date: Fri, 10 Nov 2023 15:04:52 +0000 Subject: [PATCH 2/2] date module format --- lib/ui/locations/entries/date.mjs | 47 +++++++++++++------------------ 1 file changed, 20 insertions(+), 27 deletions(-) diff --git a/lib/ui/locations/entries/date.mjs b/lib/ui/locations/entries/date.mjs index 5f73f5ca54..5d9f619ec4 100644 --- a/lib/ui/locations/entries/date.mjs +++ b/lib/ui/locations/entries/date.mjs @@ -1,48 +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 - 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 + const timeString = new Date(entry.newValue || 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 + // formatted value for 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 + 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 } - val = mapp.utils.html.node` + // return date/time input + return mapp.utils.html.node` { - // this gets user timezone - //let timezone = Intl.DateTimeFormat().resolvedOptions().timeZone; - - let unix = new Date(e.target.value).getTime() / 1000; - - entry.newValue = unix; + 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 && entry.type === 'datetime' ? `${d} ${t}` : `${d}`; } + // Assign val for non-editable entry. + const val = entry.value + && (entry.type === 'datetime' ? `${dateString} ${timeString}` : dateString) + || 'null' + const node = mapp.utils.html.node`