Fixing 24 hour forecast
This commit is contained in:
@@ -68,22 +68,6 @@ function absoluteHumidity(tempC, humidity) {
|
||||
return Math.round((humidity / 100 * svp * 2165) / (tempC + 273.15) * 1000) / 1000
|
||||
}
|
||||
|
||||
export function uvLabel(uv) {
|
||||
if (uv < 3) return 'Low'
|
||||
if (uv < 6) return 'Moderate'
|
||||
if (uv < 8) return 'High'
|
||||
if (uv < 11) return 'Very High'
|
||||
return 'Extreme'
|
||||
}
|
||||
|
||||
function cloudsLabel(fraction) {
|
||||
if (fraction < 0.1) return 'Clear'
|
||||
if (fraction < 0.3) return 'Mostly Clear'
|
||||
if (fraction < 0.6) return 'Partly Cloudy'
|
||||
if (fraction < 0.9) return 'Mostly Cloudy'
|
||||
return 'Overcast'
|
||||
}
|
||||
|
||||
// ── Daily ─────────────────────────────────────────────────────────────────────
|
||||
|
||||
const DAILY_FIELDS = [
|
||||
@@ -134,7 +118,6 @@ export async function dailyWeather(lat, lon, start, end) {
|
||||
wind_gusts: data.daily.windgusts_10m_max[i],
|
||||
wind_direction: data.daily.winddirection_10m_dominant[i],
|
||||
uv_index: uv,
|
||||
uv_index_label: uvLabel(uv),
|
||||
solar_wm2: data.daily.shortwave_radiation_sum[i],
|
||||
clouds: null,
|
||||
sunrise: data.daily.sunrise[i] ? new Date(data.daily.sunrise[i]) : null,
|
||||
@@ -176,11 +159,8 @@ export async function hourlyWeather(lat, lon, start, end) {
|
||||
}
|
||||
|
||||
return Promise.all(data.hourly.time.map(async (time, i) => {
|
||||
const dateKey = time.slice(0, 10) // "2026-03-01" from local string
|
||||
const dateKey = time.slice(0, 10)
|
||||
const sun = sunMap[dateKey] ?? {}
|
||||
// Open-Meteo local strings have no Z — append Z to treat as UTC for ms comparison
|
||||
// This works because Open-Meteo already returns times in the location's local tz
|
||||
// and sunrise/sunset are parsed the same way, so the comparison is consistent
|
||||
const t = new Date(time + 'Z').getTime()
|
||||
const daytime = sun.sunrise && sun.sunset
|
||||
? t >= new Date(sun.sunrise.toISOString().replace('Z', '') + 'Z').getTime() && t < new Date(sun.sunset.toISOString().replace('Z', '') + 'Z').getTime()
|
||||
@@ -212,9 +192,7 @@ export async function hourlyWeather(lat, lon, start, end) {
|
||||
wind_gusts: data.hourly.windgusts_10m[i],
|
||||
wind_direction: data.hourly.winddirection_10m[i],
|
||||
uv_index: uv,
|
||||
uv_index_label: uvLabel(uv),
|
||||
solar_wm2: data.hourly.shortwave_radiation[i],
|
||||
clouds_label: cloudsLabel(clouds),
|
||||
visibility: data.hourly.visibility[i] != null
|
||||
? Math.round(data.hourly.visibility[i] / 1000 * 10) / 10
|
||||
: null,
|
||||
|
||||
Reference in New Issue
Block a user