From 7893eba7a7d7ea125f9fc0f35095d4ce88fc6f25 Mon Sep 17 00:00:00 2001 From: Paul Bottein Date: Mon, 31 Mar 2025 14:58:26 +0200 Subject: [PATCH] Handle date range shift during daylight saving time days (#24868) --- src/common/datetime/calc_date.ts | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/src/common/datetime/calc_date.ts b/src/common/datetime/calc_date.ts index f298819d11..bb94dc2bbc 100644 --- a/src/common/datetime/calc_date.ts +++ b/src/common/datetime/calc_date.ts @@ -6,6 +6,10 @@ import { differenceInMilliseconds, differenceInMonths, endOfMonth, + startOfDay, + endOfDay, + differenceInDays, + addDays, } from "date-fns"; import { toZonedTime, fromZonedTime } from "date-fns-tz"; import type { HassConfig } from "home-assistant-js-websocket"; @@ -100,6 +104,32 @@ export const shiftDateRange = ( locale, config ); + } else if ( + calcDateProperty( + startDate, + (date) => startOfDay(date).getMilliseconds() === date.getMilliseconds(), + locale, + config + ) && + calcDateProperty( + endDate, + (date) => endOfDay(date).getMilliseconds() === date.getMilliseconds(), + locale, + config + ) + ) { + const difference = + ((calcDateDifferenceProperty( + endDate, + startDate, + differenceInDays, + locale, + config + ) as number) + + 1) * + (forward ? 1 : -1); + start = calcDate(startDate, addDays, locale, config, difference); + end = calcDate(endDate, addDays, locale, config, difference); } else { const difference = ((calcDateDifferenceProperty(