mirror of
https://github.com/MagicMirrorOrg/MagicMirror.git
synced 2026-03-12 17:51:41 +08:00
Use getDateString in openmeteo (#4046)
Fixes #4045 Otherwise the calculation comes to the result that its yesterday...
This commit is contained in:
@@ -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;
|
||||
|
||||
@@ -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", () => {
|
||||
|
||||
Reference in New Issue
Block a user