From d8937fa1388c312dc2be0ccb54012c51afa48c8b Mon Sep 17 00:00:00 2001 From: breken-ai <312387581+breken-ai@users.noreply.github.com> Date: Fri, 25 Sep 2026 19:41:10 -0700 Subject: [PATCH] fix(datetime): scope month values bounds to year With monthValues set, getMonthColumnData filtered months by the min and max month in every year. With min="2020-06" and monthValues set, January to May were missing from every later year too. The branch without monthValues already checks the year. Co-Authored-By: Claude Opus 5.5 (1M context) --- .../src/components/datetime/test/data.spec.ts | 31 +++++++++++++++++++ core/src/components/datetime/utils/data.ts | 9 ++++-- 2 files changed, 38 insertions(+), 2 deletions(-) diff --git a/core/src/components/datetime/test/data.spec.ts b/core/src/components/datetime/test/data.spec.ts index 506a2ab03fe..018722fffff 100644 --- a/core/src/components/datetime/test/data.spec.ts +++ b/core/src/components/datetime/test/data.spec.ts @@ -6,6 +6,7 @@ import { getToday, getCombinedDateColumnData, getTimeColumnsData, + getMonthColumnData, } from '../utils/data'; // The minutes are the same across all hour cycles, so we don't check those @@ -516,3 +517,33 @@ describe('getCombinedDateColumnData', () => { ]); }); }); + +describe('getMonthColumnData()', () => { + const monthValues = [1, 3, 5, 7, 9, 11]; + const getValues = (refParts: DatetimeParts, minParts?: DatetimeParts, maxParts?: DatetimeParts) => + getMonthColumnData('en-US', refParts, minParts, maxParts, monthValues).map((option) => option.value); + + it('should apply the min month only in the min year when monthValues is set', () => { + const minParts = { month: 6, day: 1, year: 2020 }; + + expect(getValues({ month: 5, day: 1, year: 2020 }, minParts)).toEqual([7, 9, 11]); + expect(getValues({ month: 3, day: 1, year: 2024 }, minParts)).toEqual([1, 3, 5, 7, 9, 11]); + }); + + it('should apply the max month only in the max year when monthValues is set', () => { + const maxParts = { month: 4, day: 30, year: 2025 }; + + expect(getValues({ month: 3, day: 1, year: 2025 }, undefined, maxParts)).toEqual([1, 3]); + expect(getValues({ month: 9, day: 1, year: 2024 }, undefined, maxParts)).toEqual([1, 3, 5, 7, 9, 11]); + }); + + it('should match the months shown when monthValues is not set', () => { + const minParts = { month: 6, day: 1, year: 2020 }; + const maxParts = { month: 4, day: 30, year: 2025 }; + const refParts = { month: 3, day: 1, year: 2024 }; + + const allMonths = getMonthColumnData('en-US', refParts, minParts, maxParts).map((option) => option.value); + expect(allMonths).toEqual([1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12]); + expect(getValues(refParts, minParts, maxParts)).toEqual([1, 3, 5, 7, 9, 11]); + }); +}); diff --git a/core/src/components/datetime/utils/data.ts b/core/src/components/datetime/utils/data.ts index bd6f328752e..a8db2ae0cf4 100644 --- a/core/src/components/datetime/utils/data.ts +++ b/core/src/components/datetime/utils/data.ts @@ -359,10 +359,15 @@ export const getMonthColumnData = ( if (monthValues !== undefined) { let processedMonths = monthValues; - if (maxParts?.month !== undefined) { + /** + * The max and min months only apply to the + * max and min years. For example, with a max of + * 2025-03, every month of 2024 is still allowed. + */ + if (maxParts?.month !== undefined && maxParts.year === year) { processedMonths = processedMonths.filter((month) => month <= maxParts.month!); } - if (minParts?.month !== undefined) { + if (minParts?.month !== undefined && minParts.year === year) { processedMonths = processedMonths.filter((month) => month >= minParts.month!); }