Added daytime property

This commit is contained in:
2026-06-24 15:31:00 -04:00
parent 367c35461b
commit 694b9bad24
3 changed files with 27 additions and 2 deletions

View File

@@ -136,10 +136,11 @@ export async function dailyWeather(lat, lon, start, end) {
const clouds = null // not available in daily
return {
time,
label: WMO[code] || 'Unknown',
icon,
code,
time,
daytime: !!data.daily.sunrise[i],
temperature: temp,
temperature_max: temp,
temperature_min: data.daily.temperature_2m_min[i],
@@ -183,7 +184,20 @@ export async function hourlyWeather(lat, lon, start, end) {
const data = await cachedFetch(`hourly_${lat}_${lon}_${startStr}_${endStr}`, url)
if (!data?.hourly?.time) return []
const sunMap = {}
if (data.daily?.time) {
data.daily.time.forEach((date, i) => {
sunMap[date] = { sunrise: data.daily.sunrise[i], sunset: data.daily.sunset[i] }
})
}
return Promise.all(data.hourly.time.map(async (time, i) => {
const date = time.slice(0, 10)
const sun = sunMap[date] ?? {}
const t = new Date(time).getTime()
const daytime = sun.sunrise && sun.sunset
? t >= new Date(sun.sunrise).getTime() && t < new Date(sun.sunset).getTime()
: false
const code = data.hourly.weathercode[i]
const icon = await ensureIcon(code).catch(() => null)
const temp = data.hourly.temperature_2m[i]
@@ -193,6 +207,7 @@ export async function hourlyWeather(lat, lon, start, end) {
return {
time: time.slice(0, 16),
daytime,
label: WMO[code] || 'Unknown',
icon,
code,