From fcf844cf1a76cbdac7477baebc2905dd252d9111 Mon Sep 17 00:00:00 2001 From: SmartCoder Date: Mon, 12 Jan 2026 12:53:08 +0100 Subject: [PATCH] Fix issue #28896: "Last 12 months" in the Datetime Picker selects last year (#28902) Summary of the fix: The Problem: now-12m was selecting the calendar year (Jan 1st to Dec 31st) instead of the last 12 months from now It used startOfMonth and endOfMonth, which snap to month boundaries The Solution: Changed to match the now-7d and now-30d pattern Now uses subMonths(today, 12) for start and subMonths(today, 0) (which equals today) for end This gives exactly the last 12 months (365/366 days) ending at the current time The Fix: // Before (WRONG):calcDate(subMonths(today, 12), startOfMonth, ...) // Jan 1st of 12 months agocalcDate(subMonths(today, 1), endOfMonth, ...) // Dec 31st of last month// After (CORRECT):calcDate(today, subMonths, hass.locale, hass.config, 12) // 12 months ago from nowcalcDate(today, subMonths, hass.locale, hass.config, 0) // now --- src/common/datetime/calc_date_range.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/common/datetime/calc_date_range.ts b/src/common/datetime/calc_date_range.ts index 79a2d729d0..1d7580cae6 100644 --- a/src/common/datetime/calc_date_range.ts +++ b/src/common/datetime/calc_date_range.ts @@ -93,8 +93,8 @@ export const calcDateRange = ( ]; case "now-12m": return [ - calcDate(subMonths(today, 12), startOfMonth, hass.locale, hass.config), - calcDate(subMonths(today, 1), endOfMonth, hass.locale, hass.config), + calcDate(today, subMonths, hass.locale, hass.config, 12), + calcDate(today, subMonths, hass.locale, hass.config, 0), ]; case "now-1h": return [