From 0bf1f387189864a08afe80657d0bd20fc3f1eaae Mon Sep 17 00:00:00 2001 From: Will Bradley Date: Wed, 16 Jul 2025 18:02:15 -0700 Subject: [PATCH] Account for timezones in statusAsOf --- public/city-select.html | 2 +- public/dashboard.html | 20 +++++++++++++++++--- server.js | 1 + 3 files changed, 19 insertions(+), 4 deletions(-) diff --git a/public/city-select.html b/public/city-select.html index f598762..72e858f 100644 --- a/public/city-select.html +++ b/public/city-select.html @@ -184,7 +184,7 @@
-

💧 Water Station Tracker

+

💧 CoolingStations.org

Select a city to view water stations

diff --git a/public/dashboard.html b/public/dashboard.html index 11dd36c..6104a15 100644 --- a/public/dashboard.html +++ b/public/dashboard.html @@ -701,9 +701,14 @@ activeStationId = stationId; // Track which station we're updating document.getElementById('updateModal').style.display = 'block'; - // Set current date/time as default + // Set current date/time as default in local timezone const now = new Date(); - const localDateTime = new Date(now.getTime() - now.getTimezoneOffset() * 60000).toISOString().slice(0, 16); + const year = now.getFullYear(); + const month = String(now.getMonth() + 1).padStart(2, '0'); + const day = String(now.getDate()).padStart(2, '0'); + const hours = String(now.getHours()).padStart(2, '0'); + const minutes = String(now.getMinutes()).padStart(2, '0'); + const localDateTime = `${year}-${month}-${day}T${hours}:${minutes}`; document.getElementById('statusAsOf').value = localDateTime; // Center map on selected station @@ -892,10 +897,19 @@ } const formData = new FormData(e.target); + const statusAsOfLocal = formData.get('statusAsOf'); + + // Convert local datetime to UTC for server + let statusAsOfUTC = null; + if (statusAsOfLocal) { + const localDate = new Date(statusAsOfLocal); + statusAsOfUTC = localDate.toISOString(); + } + const data = { description: formData.get('description'), estimatedHours: formData.get('estimatedHours'), - statusAsOf: formData.get('statusAsOf') + statusAsOf: statusAsOfUTC }; try { diff --git a/server.js b/server.js index 9ff6e23..9990192 100644 --- a/server.js +++ b/server.js @@ -400,6 +400,7 @@ app.post('/api/stations/:id/update', (req, res) => { const stationId = req.params.id; // Use provided status date/time or current time + // statusAsOf now comes as UTC ISO string from client const refillTime = statusAsOf ? new Date(statusAsOf) : new Date(); const estimatedEmptyTime = new Date(refillTime);