Account for timezones in statusAsOf

This commit is contained in:
Will Bradley 2025-07-16 18:02:15 -07:00
parent 7b332f873a
commit 0bf1f38718
3 changed files with 19 additions and 4 deletions

View File

@ -184,7 +184,7 @@
<body> <body>
<div class="container"> <div class="container">
<div class="header"> <div class="header">
<h1>💧 Water Station Tracker</h1> <h1>💧 CoolingStations.org</h1>
<p>Select a city to view water stations</p> <p>Select a city to view water stations</p>
</div> </div>

View File

@ -701,9 +701,14 @@
activeStationId = stationId; // Track which station we're updating activeStationId = stationId; // Track which station we're updating
document.getElementById('updateModal').style.display = 'block'; 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 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; document.getElementById('statusAsOf').value = localDateTime;
// Center map on selected station // Center map on selected station
@ -892,10 +897,19 @@
} }
const formData = new FormData(e.target); 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 = { const data = {
description: formData.get('description'), description: formData.get('description'),
estimatedHours: formData.get('estimatedHours'), estimatedHours: formData.get('estimatedHours'),
statusAsOf: formData.get('statusAsOf') statusAsOf: statusAsOfUTC
}; };
try { try {

View File

@ -400,6 +400,7 @@ app.post('/api/stations/:id/update', (req, res) => {
const stationId = req.params.id; const stationId = req.params.id;
// Use provided status date/time or current time // 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 refillTime = statusAsOf ? new Date(statusAsOf) : new Date();
const estimatedEmptyTime = new Date(refillTime); const estimatedEmptyTime = new Date(refillTime);