Daily forecast fix?

This commit is contained in:
2026-06-24 11:25:38 -04:00
parent 8019dabe2a
commit 3cf62b8e11
2 changed files with 6 additions and 7 deletions

View File

@@ -112,8 +112,6 @@ const DAILY_WEATHER = [
const HOURLY_AQ = [
'pm10', 'pm2_5', 'carbon_monoxide', 'nitrogen_dioxide', 'sulphur_dioxide',
'ozone', 'aerosol_optical_depth', 'dust', 'uv_index',
'alder_pollen', 'birch_pollen', 'grass_pollen',
'mugwort_pollen', 'olive_pollen', 'ragweed_pollen',
].join(',')
const HOURLY_MARINE = [

View File

@@ -84,15 +84,16 @@ app.get('/api/hourly', async (req, res) => {
app.get('/api/daily', async (req, res) => {
const {fields} = req.query;
const start = req.query.start || new Date(new Date().setHours(0, 0, 0, 0)).toISOString();
const start = req.query.start || new Date(new Date().setHours(0, 0, 0, 0));
let now = new Date();
now.setHours(0, 0, 0, 0);
now = now.toISOString();
const end = req.query.end || new Date().toISOString();
let next = new Date(now);
next.setDate(now.getDate() + 1);
const end = req.query.end || new Date();
const coords = await getCoords();
const [sensor, meteo] = await Promise.allSettled([
now > start ? queryDaily(start, now) : Promise.resolve([]),
getOpenMeteo(coords.latitude, coords.longitude, now, end),
now > start ? queryDaily(start.toISOString(), now.toISOString()) : Promise.resolve([]),
getOpenMeteo(coords.latitude, coords.longitude, (start.getTime() > next.getTime() ? start : next).toISOString(), end.toISOString()),
]);
const history = sensor.status === 'fulfilled' ? sensor.value : [];
const forecast = meteo.status === 'fulfilled' ? meteo.value.daily : [];