Use getDateString in openmeteo (#4046)

Fixes #4045 

Otherwise the calculation comes to the result that its yesterday...
This commit is contained in:
Veeck
2026-03-01 15:28:06 +01:00
committed by GitHub
parent 587bc2571e
commit 06b1361457
2 changed files with 30 additions and 2 deletions

View File

@@ -270,13 +270,13 @@ class OpenMeteoProvider {
const endDate = new Date(startDate);
endDate.setDate(endDate.getDate() + Math.max(0, Math.min(7, maxNumberOfDays)));
params.start_date = startDate.toISOString().split("T")[0];
params.start_date = getDateString(startDate);
switch (this.config.type) {
case "hourly":
case "daily":
case "forecast":
params.end_date = endDate.toISOString().split("T")[0];
params.end_date = getDateString(endDate);
break;
case "current":
params.current_weather = true;

View File

@@ -79,6 +79,34 @@ describe("OpenMeteoProvider", () => {
await provider.initialize();
expect(provider.locationName).toBe("Munich, BY");
});
it("should build query dates from local date, not ISO UTC conversion", async () => {
const toISOStringSpy = vi.spyOn(Date.prototype, "toISOString").mockReturnValue("2000-01-01T00:00:00.000Z");
try {
const provider = new OpenMeteoProvider({
lat: 48.14,
lon: 11.58,
type: "current"
});
await provider.initialize();
const url = new URL(provider.fetcher.url);
const params = url.searchParams;
const now = new Date();
const expectedToday = [
now.getFullYear(),
String(now.getMonth() + 1).padStart(2, "0"),
String(now.getDate()).padStart(2, "0")
].join("-");
expect(params.get("start_date")).toBe(expectedToday);
expect(params.get("end_date")).toBe(expectedToday);
expect(params.get("start_date")).not.toBe("2000-01-01");
} finally {
toISOStringSpy.mockRestore();
}
});
});
describe("Current Weather Parsing", () => {