Skip to content

Commit

Permalink
Allow meteo hourly data matches from +-1h
Browse files Browse the repository at this point in the history
  • Loading branch information
kimmobrunfeldt committed Oct 29, 2023
1 parent 7d0dfb4 commit c2f9758
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions render/src/weather/weather.ts
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ export function calculateShortTermForecast(
)
}
const foundMeteoHourData = attrsByTime(meteoForecastData.hourly).find((d) =>
dateFns.isEqual(d.time, time)
isApproximatelyMatchingDate(d.time, time)
)

const nextIndex = index + 1
Expand Down Expand Up @@ -445,8 +445,7 @@ function findWeatherSymbolForDay(

// Take DST into account when finding matching date
const found = dates.find(
(d) =>
dateFns.differenceInSeconds(d.time, time) <= dateFns.hoursToSeconds(1)
(d) => isApproximatelyMatchingDate(d.time, time)
)
if (!found) {
logger.error('Unable to find matching date', {
Expand All @@ -465,3 +464,7 @@ function isBetweenInclusive(time: Date, start: Date, end: Date): boolean {
(dateFns.isBefore(time, end) || dateFns.isEqual(time, end))
)
}

function isApproximatelyMatchingDate(a: Date, b: Date): boolean {
return Math.abs(dateFns.differenceInSeconds(a, b)) <= dateFns.hoursToSeconds(1)
}

0 comments on commit c2f9758

Please sign in to comment.