Skip to content

Commit 06b1361

Browse files
authored
Use getDateString in openmeteo (#4046)
Fixes #4045 Otherwise the calculation comes to the result that its yesterday...
1 parent 587bc25 commit 06b1361

File tree

2 files changed

+30
-2
lines changed

2 files changed

+30
-2
lines changed

defaultmodules/weather/providers/openmeteo.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -270,13 +270,13 @@ class OpenMeteoProvider {
270270
const endDate = new Date(startDate);
271271
endDate.setDate(endDate.getDate() + Math.max(0, Math.min(7, maxNumberOfDays)));
272272

273-
params.start_date = startDate.toISOString().split("T")[0];
273+
params.start_date = getDateString(startDate);
274274

275275
switch (this.config.type) {
276276
case "hourly":
277277
case "daily":
278278
case "forecast":
279-
params.end_date = endDate.toISOString().split("T")[0];
279+
params.end_date = getDateString(endDate);
280280
break;
281281
case "current":
282282
params.current_weather = true;

tests/unit/modules/default/weather/providers/openmeteo_spec.js

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,34 @@ describe("OpenMeteoProvider", () => {
7979
await provider.initialize();
8080
expect(provider.locationName).toBe("Munich, BY");
8181
});
82+
83+
it("should build query dates from local date, not ISO UTC conversion", async () => {
84+
const toISOStringSpy = vi.spyOn(Date.prototype, "toISOString").mockReturnValue("2000-01-01T00:00:00.000Z");
85+
try {
86+
const provider = new OpenMeteoProvider({
87+
lat: 48.14,
88+
lon: 11.58,
89+
type: "current"
90+
});
91+
92+
await provider.initialize();
93+
94+
const url = new URL(provider.fetcher.url);
95+
const params = url.searchParams;
96+
const now = new Date();
97+
const expectedToday = [
98+
now.getFullYear(),
99+
String(now.getMonth() + 1).padStart(2, "0"),
100+
String(now.getDate()).padStart(2, "0")
101+
].join("-");
102+
103+
expect(params.get("start_date")).toBe(expectedToday);
104+
expect(params.get("end_date")).toBe(expectedToday);
105+
expect(params.get("start_date")).not.toBe("2000-01-01");
106+
} finally {
107+
toISOStringSpy.mockRestore();
108+
}
109+
});
82110
});
83111

84112
describe("Current Weather Parsing", () => {

0 commit comments

Comments
 (0)