From 06aba46ec6a0a1e944c88fe99d9bc6181a73cc1c Mon Sep 17 00:00:00 2001 From: Pete Date: Wed, 4 Dec 2024 11:59:34 +0100 Subject: [PATCH] FIX: better fix for leap year problem --- homeassistant/components/recorder/util.py | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/homeassistant/components/recorder/util.py b/homeassistant/components/recorder/util.py index 125b354211eb5d..a99d2d70b8b0c9 100644 --- a/homeassistant/components/recorder/util.py +++ b/homeassistant/components/recorder/util.py @@ -897,12 +897,8 @@ def resolve_period( start_time = (start_time + timedelta(days=cal_offset * 31)).replace(day=1) end_time = (start_time + timedelta(days=31)).replace(day=1) else: # calendar_period = "year" - start_time = start_of_day.replace(month=12, day=31) - # This works for 100+ years of offset - start_time = (start_time + timedelta(days=cal_offset * 366)).replace( - month=1, day=1 - ) - end_time = (start_time + timedelta(days=366)).replace(day=1) + start_time = start_of_day.replace(month=1, day=1, year=start_of_day.year + cal_offset) + end_time = start_time.replace(month=12, day=31) start_time = dt_util.as_utc(start_time) end_time = dt_util.as_utc(end_time)