fixes problems with daylight-saving-time in weather provider openmeteo (#3931)

fix for #3930
This commit is contained in:
Karsten Hassel
2025-11-01 13:46:58 +01:00
committed by GitHub
parent 961b3c96d6
commit 1e5d127d44
2 changed files with 13 additions and 1 deletions

View File

@@ -280,13 +280,24 @@ WeatherProvider.register("openmeteo", {
return `${this.config.apiBase}/forecast?${this.getQueryParameters()}`;
},
// fix daylight-saving-time differences
checkDST (dt) {
const uxdt = moment.unix(dt);
const nowDST = moment().isDST();
if (nowDST === moment(uxdt).isDST()) {
return uxdt;
} else {
return uxdt.add(nowDST ? +1 : -1, "hour");
}
},
// Transpose hourly and daily data matrices
transposeDataMatrix (data) {
return data.time.map((_, index) => Object.keys(data).reduce((row, key) => {
return {
...row,
// Parse time values as momentjs instances
[key]: ["time", "sunrise", "sunset"].includes(key) ? moment.unix(data[key][index]) : data[key][index]
[key]: ["time", "sunrise", "sunset"].includes(key) ? this.checkDST(data[key][index]) : data[key][index]
};
}, {}));
},