mirror of
https://github.com/home-assistant/core.git
synced 2025-07-30 02:38:10 +02:00
Improve recorder util resolve_period (#132264)
This commit is contained in:
@ -892,15 +892,14 @@ def resolve_period(
|
||||
start_time += timedelta(days=cal_offset * 7)
|
||||
end_time = start_time + timedelta(weeks=1)
|
||||
elif calendar_period == "month":
|
||||
start_time = start_of_day.replace(day=28)
|
||||
# This works for up to 48 months of offset
|
||||
start_time = (start_time + timedelta(days=cal_offset * 31)).replace(day=1)
|
||||
month_now = start_of_day.month
|
||||
new_month = (month_now - 1 + cal_offset) % 12 + 1
|
||||
new_year = start_of_day.year + (month_now - 1 + cal_offset) // 12
|
||||
start_time = start_of_day.replace(year=new_year, month=new_month, 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
|
||||
start_time = start_of_day.replace(
|
||||
year=start_of_day.year + cal_offset, month=1, day=1
|
||||
)
|
||||
end_time = (start_time + timedelta(days=366)).replace(day=1)
|
||||
|
||||
|
Reference in New Issue
Block a user