From 402dc271807d0528bed52b17a0e9e0210282175a Mon Sep 17 00:00:00 2001 From: Oskar Date: Thu, 3 Dec 2020 14:33:55 +0100 Subject: [PATCH] Web: resolve #15 by converting UTC to local time for input limits --- web/index.html | 13 +++++++++++-- web/viewdata.html | 14 +++++++++----- 2 files changed, 20 insertions(+), 7 deletions(-) diff --git a/web/index.html b/web/index.html index c9705c4..d8db72a 100644 --- a/web/index.html +++ b/web/index.html @@ -223,6 +223,15 @@ } + function localISOTimeMinutes(date) { + + var tzoffset = date.getTimezoneOffset() * 60000; //offset in milliseconds + var localISOTime = (new Date(date - tzoffset)).toISOString().slice(0, -1); + + return localISOTime.split(':').slice(0,2).join(':') + + } + function handleRequest(res) { var reqt = { @@ -240,10 +249,10 @@ var d = new Date(json.arrival.time) var dInfo = d.toString('en-GB').split(' ').slice(0,5).join(' ') aInfo = `Your last arrival was on ${dInfo} in room ${json.arrival.room}.` - minD = `min="${json.arrival.time.split(':').slice(0,2).join(':')}"` + minD = `min="${localISOTimeMinutes(d)}"` } - var now = new Date().toISOString().split(':').slice(0,2).join(':') + var now = localISOTimeMinutes(new Date()) document.body.innerHTML += `
diff --git a/web/viewdata.html b/web/viewdata.html index 5de2cdb..51718c4 100644 --- a/web/viewdata.html +++ b/web/viewdata.html @@ -227,12 +227,16 @@ } - var now = new Date() - var localISODate = new Date(now.getTime() - - (now.getTimezoneOffset() * 60000)).toISOString(); + function localISOTimeMinutes(date) { - document.querySelector('input#end').value = - localISODate.split(':').slice(0,2).join(':') + var tzoffset = date.getTimezoneOffset() * 60000; //offset in milliseconds + var localISOTime = (new Date(date - tzoffset)).toISOString().slice(0, -1); + + return localISOTime.split(':').slice(0,2).join(':') + + } + + document.querySelector('input#end').value = localISOTimeMinutes(new Date()) var scrollbox = document.querySelector('.scroll') var timehead = document.querySelector('#timeheader')