Auto-fill current time in correct time zone

We cannot use valueAsDate because this converts to UTC which is not desired
This commit is contained in:
RunasSudo 2024-08-26 18:36:59 +10:00
parent 3bf624f9dd
commit c1f2b0c908
Signed by: RunasSudo
GPG Key ID: 7234E476BF21C61A

View File

@ -233,15 +233,23 @@
// ------------
// Prefill form
let dateNow = new Date();
dateNow.setSeconds(0);
dateNow.setMilliseconds(0);
function dateToISOStringLocal(date) {
function pad(n) {
if (n < 10) {
return '0' + n;
}
return '' + n;
}
return date.getFullYear() + '-' + pad(date.getMonth() + 1) + '-' + pad(date.getDate()) + 'T' + pad(date.getHours()) + ':' + pad(date.getMinutes());
}
let dateNow = dateToISOStringLocal(new Date());
if (document.getElementById('time_birth').value === '') {
document.getElementById('time_birth').valueAsDate = dateNow;
document.getElementById('time_birth').value = dateNow;
}
if (document.getElementById('time_measurement').value === '') {
document.getElementById('time_measurement').valueAsDate = dateNow;
document.getElementById('time_measurement').value = dateNow;
}
// --------------------------