diff --git a/server/src/celestial.mjs b/server/src/celestial.mjs index 35a765f..1b0ce04 100644 --- a/server/src/celestial.mjs +++ b/server/src/celestial.mjs @@ -53,14 +53,10 @@ function sunriseSunset(lat, lon, date = new Date()) { const H = Math.acos(cosH) * DEG; const rise = jdnToDate(jnoon - H / 360); const set = jdnToDate(jnoon + H / 360); - const noon_d = jdnToDate(jnoon); - - // Round to nearest second, drop milliseconds - const fmt = d => new Date(Math.round(d.getTime() / 1000) * 1000).toISOString(); return { - sunrise: fmt(rise), - sunset: fmt(set), + sunrise: rise, + sunset: set, daylight: Math.round((set - rise) / 36000) / 100, daytime: cosH < -1 }; @@ -162,8 +158,8 @@ function nextMoonEvents(date = new Date()) { const toNew = (cycle - phase) % cycle; const toFull = phase < 14.76 ? 14.76 - phase : cycle - phase + 14.76; return { - moon_new: jdnToDate(jd + toNew).toISOString(), - moon_full: jdnToDate(jd + toFull).toISOString(), + moon_new: jdnToDate(jd + toNew), + moon_full: jdnToDate(jd + toFull), }; } @@ -200,8 +196,8 @@ function moonriseMoonset(lat, lon, date = new Date()) { ) * DEG; if(prev !== null) { - if(prev < 0 && elev >= 0 && !moonrise) moonrise = new Date(t.getTime() - 5 * 60000).toISOString(); - if(prev >= 0 && elev < 0 && !moonset) moonset = new Date(t.getTime() - 5 * 60000).toISOString(); + if(prev < 0 && elev >= 0 && !moonrise) moonrise = new Date(t.getTime() - 5 * 60000); + if(prev >= 0 && elev < 0 && !moonset) moonset = new Date(t.getTime() - 5 * 60000); } prev = elev; if(moonrise && moonset) break; diff --git a/server/src/forecast.mjs b/server/src/forecast.mjs index d90e1bb..f59f42a 100644 --- a/server/src/forecast.mjs +++ b/server/src/forecast.mjs @@ -107,7 +107,7 @@ export async function get24HourForecast(currentSensors) { const sixAgo = new Date(now - 6 * 3600 * 1000); const coords = await getCoords(); - const history = await queryHourly(sixAgo.toISOString(), now.toISOString()); + const history = await queryHourly(sixAgo, now); // Extract trend series from history const pressures = history.map(r => r.pressure_hpa).filter(Number.isFinite); diff --git a/server/src/server.mjs b/server/src/server.mjs index 9f171f3..5894eaf 100644 --- a/server/src/server.mjs +++ b/server/src/server.mjs @@ -79,7 +79,7 @@ app.get('/api/hourly', async (req, res) => { historyEnd.setMinutes(0, 0, 0) const [historyResult] = await Promise.allSettled([ - start < now ? queryHourly(start.toISOString(), historyEnd.toISOString()) : Promise.resolve([]) + start < now ? queryHourly(start, historyEnd) : Promise.resolve([]) ]) const history = historyResult.status === 'fulfilled' ? historyResult.value : [] @@ -112,13 +112,13 @@ app.get('/api/daily', async (req, res) => { const coords = await getCoords() // Does the requested window overlap with today (the 24h forecast window)? - const todayStr = now.toISOString().slice(0, 10) + const todayStr = now const { summary } = await ensureForecast() const usePhysics = summary && start <= next && end >= now // Past influx history (days before today) const [sensorResult] = await Promise.allSettled([ - start < now ? queryDaily(start.toISOString(), now.toISOString()) : Promise.resolve([]) + start < now ? queryDaily(start, now) : Promise.resolve([]) ]) const history = sensorResult.status === 'fulfilled' ? sensorResult.value : []