Skip to content

Commit 1e5d127

Browse files
authored
fixes problems with daylight-saving-time in weather provider openmeteo (#3931)
fix for #3930
1 parent 961b3c9 commit 1e5d127

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ planned for 2026-01-01
2929
- fixed eslint warnings shown in #3911 and updated npm publish docs (#3913)
3030
- [core] refactor: replace `express-ipfilter` with lightweight custom middleware (#3917) - This fixes security issue [CVE-2023-42282](https://github.com/advisories/GHSA-78xj-cgh5-2h22), which is not very likely to be exploitable in MagicMirror² setups, but still should be fixed.
3131
- fixed the Environment Canada weather URL (#3912) and now converts a windspeed of 'calm' to 0
32+
- fixed problems with daylight-saving-time in weather provider `openmeto` (#3930, #3931)
3233

3334
### Updated
3435

modules/default/weather/providers/openmeteo.js

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -280,13 +280,24 @@ WeatherProvider.register("openmeteo", {
280280
return `${this.config.apiBase}/forecast?${this.getQueryParameters()}`;
281281
},
282282

283+
// fix daylight-saving-time differences
284+
checkDST (dt) {
285+
const uxdt = moment.unix(dt);
286+
const nowDST = moment().isDST();
287+
if (nowDST === moment(uxdt).isDST()) {
288+
return uxdt;
289+
} else {
290+
return uxdt.add(nowDST ? +1 : -1, "hour");
291+
}
292+
},
293+
283294
// Transpose hourly and daily data matrices
284295
transposeDataMatrix (data) {
285296
return data.time.map((_, index) => Object.keys(data).reduce((row, key) => {
286297
return {
287298
...row,
288299
// Parse time values as momentjs instances
289-
[key]: ["time", "sunrise", "sunset"].includes(key) ? moment.unix(data[key][index]) : data[key][index]
300+
[key]: ["time", "sunrise", "sunset"].includes(key) ? this.checkDST(data[key][index]) : data[key][index]
290301
};
291302
}, {}));
292303
},

0 commit comments

Comments
 (0)