fix(datetime): correct year is set in wheel picker (#25896)

resolves #25895
This commit is contained in:
Liam DeBeasi
2022-09-09 14:08:27 -05:00
committed by GitHub
parent b598de63da
commit fb653ebe67
4 changed files with 29 additions and 9 deletions

View File

@ -1415,7 +1415,6 @@ export class Datetime implements ComponentInterface {
const result = getCombinedDateColumnData(
locale,
workingParts,
todayParts,
min,
max,

View File

@ -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' },
]);
});
});

View File

@ -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);
});
});
});

View File

@ -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,
});
});