diff --git a/static/js/utils.js b/static/js/utils.js index fc3aa78..1203f92 100644 --- a/static/js/utils.js +++ b/static/js/utils.js @@ -1,4 +1,10 @@ const WeatherUtils = { + formatDatetimeLocal(date) { + const offsetMinutes = date.getTimezoneOffset(); + const local = new Date(date.getTime() - offsetMinutes * 60 * 1000); + return local.toISOString().slice(0, 16); + }, + initializeDateInputs() { const now = new Date(); const startDate = new Date(now.getTime() - 24 * 60 * 60 * 1000); @@ -8,10 +14,10 @@ const WeatherUtils = { const endDateInput = document.getElementById('endDate'); if (startDateInput) { - startDateInput.value = startDate.toISOString().slice(0, 16); + startDateInput.value = this.formatDatetimeLocal(startDate); } if (endDateInput) { - endDateInput.value = endDate.toISOString().slice(0, 16); + endDateInput.value = this.formatDatetimeLocal(endDate); } },