diff --git a/core/src/components/datetime/datetime.tsx b/core/src/components/datetime/datetime.tsx index bb8d0bad26..0963d867df 100644 --- a/core/src/components/datetime/datetime.tsx +++ b/core/src/components/datetime/datetime.tsx @@ -1415,7 +1415,6 @@ export class Datetime implements ComponentInterface { const result = getCombinedDateColumnData( locale, - workingParts, todayParts, min, max, diff --git a/core/src/components/datetime/test/data.spec.ts b/core/src/components/datetime/test/data.spec.ts index 959ed25456..73420d2f6a 100644 --- a/core/src/components/datetime/test/data.spec.ts +++ b/core/src/components/datetime/test/data.spec.ts @@ -1,4 +1,4 @@ -import { generateMonths, getDaysOfWeek, generateTime, getToday } from '../utils/data'; +import { generateMonths, getDaysOfWeek, generateTime, getToday, getCombinedDateColumnData } from '../utils/data'; describe('generateMonths()', () => { it('should generate correct month data', () => { @@ -342,3 +342,25 @@ describe('getToday', () => { expect(res).toEqual('2022-02-21T18:30:00.000Z'); }); }); + +describe('getCombinedDateColumnData', () => { + it('should return correct data with dates across years', () => { + const { parts, items } = getCombinedDateColumnData( + 'en-US', + { day: 1, month: 1, year: 2021 }, + { day: 31, month: 12, year: 2020 }, + { day: 2, month: 1, year: 2021 } + ); + + expect(parts).toEqual([ + { month: 12, year: 2020, day: 31 }, + { month: 1, year: 2021, day: 1 }, + { month: 1, year: 2021, day: 2 }, + ]); + expect(items).toEqual([ + { text: 'Thu, Dec 31', value: '2020-12-31' }, + { text: 'Today', value: '2021-1-1' }, + { text: 'Sat, Jan 2', value: '2021-1-2' }, + ]); + }); +}); diff --git a/core/src/components/datetime/test/prefer-wheel/datetime.e2e.ts b/core/src/components/datetime/test/prefer-wheel/datetime.e2e.ts index 7ae1f3ca3c..a1c5c2aec9 100644 --- a/core/src/components/datetime/test/prefer-wheel/datetime.e2e.ts +++ b/core/src/components/datetime/test/prefer-wheel/datetime.e2e.ts @@ -251,7 +251,7 @@ test.describe('datetime: prefer wheel', () => { const dateValues = page.locator('.date-column .picker-item:not(.picker-item-empty)'); - expect(await dateValues.count()).toBe(427); + expect(await dateValues.count()).toBe(397); }); }); test.describe('datetime: time-date wheel rendering', () => { @@ -356,7 +356,7 @@ test.describe('datetime: prefer wheel', () => { const dateValues = page.locator('.date-column .picker-item:not(.picker-item-empty)'); - expect(await dateValues.count()).toBe(427); + expect(await dateValues.count()).toBe(397); }); }); }); diff --git a/core/src/components/datetime/utils/data.ts b/core/src/components/datetime/utils/data.ts index 073541dbe1..1f8c134f03 100644 --- a/core/src/components/datetime/utils/data.ts +++ b/core/src/components/datetime/utils/data.ts @@ -441,7 +441,6 @@ const getAllMonthsInRange = (currentParts: DatetimeParts, maxParts: DatetimePart */ export const getCombinedDateColumnData = ( locale: string, - refParts: DatetimeParts, todayParts: DatetimeParts, minParts: DatetimeParts, maxParts: DatetimeParts, @@ -473,7 +472,7 @@ export const getCombinedDateColumnData = ( * of work as the text. */ months.forEach((monthObject) => { - const referenceMonth = { month: monthObject.month, day: null, year: refParts.year }; + const referenceMonth = { month: monthObject.month, day: null, year: monthObject.year }; const monthDays = getDayColumnData(locale, referenceMonth, minParts, maxParts, dayValues, { month: 'short', day: 'numeric', @@ -492,7 +491,7 @@ export const getCombinedDateColumnData = ( */ dateColumnItems.push({ text: isToday ? getTodayLabel(locale) : dayObject.text, - value: `${refParts.year}-${monthObject.month}-${dayObject.value}`, + value: `${referenceMonth.year}-${referenceMonth.month}-${dayObject.value}`, }); /** @@ -506,8 +505,8 @@ export const getCombinedDateColumnData = ( * updating the picker column value. */ dateParts.push({ - month: monthObject.month, - year: refParts.year, + month: referenceMonth.month, + year: referenceMonth.year, day: dayObject.value as number, }); });