Skip to content

Commit

Permalink
#256 Fixed forecast not updating on colder days
Browse files Browse the repository at this point in the history
  • Loading branch information
victrme committed Dec 2, 2023
1 parent 31da90e commit f29a8e3
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions src/scripts/features/weather.ts
Original file line number Diff line number Diff line change
Expand Up @@ -331,19 +331,21 @@ async function request(data: Weather, lastWeather?: LastWeather, currentOnly?: b

if (onecall.hourly) {
const date = new Date()
const alltemps: number[] = []

if (date.getHours() > getSunsetHour()) {
date.setDate(date.getDate() + 1)
}

for (const elem of onecall.hourly) {
if (new Date(elem.dt * 1000).getDate() === date.getDate() && forecasted_high < elem.temp) {
forecasted_high = Math.round(elem.temp)
for (const item of onecall.hourly) {
if (new Date(item.dt * 1000).getDate() === date.getDate()) {
alltemps.push(item.temp)
}
}

date.setHours(0, 0, 0, 0)
forecasted_timestamp = Math.floor(date.getTime() / 1000)
forecasted_high = Math.round(Math.max(...alltemps))
}

suntime.update(sunrise, sunset)
Expand Down

0 comments on commit f29a8e3

Please sign in to comment.