diff --git a/core/src/components/datetime/test/data.spec.ts b/core/src/components/datetime/test/data.spec.ts index ece8444ae5..bca609eb9c 100644 --- a/core/src/components/datetime/test/data.spec.ts +++ b/core/src/components/datetime/test/data.spec.ts @@ -205,6 +205,36 @@ describe('generateTime()', () => { expect(minutes).toStrictEqual([10, 15, 20]); }); + it('should allow both am/pm when min is am and max is pm', () => { + // https://github.com/ionic-team/ionic-framework/issues/26216 + const today = { + day: 22, + month: 5, + year: 2021, + hour: 5, + minute: 43, + }; + const min = { + day: 22, + month: 5, + year: 2021, + hour: 11, + minute: 14, + }; + const max = { + day: 22, + month: 5, + year: 2021, + hour: 12, + minute: 14, + }; + + const { am, pm } = generateTime(today, 'h12', min, max); + + expect(am).toBe(true); + expect(pm).toBe(true); + }); + describe('hourCycle is 23', () => { it('should return hours in 24 hour format', () => { const refValue = { diff --git a/core/src/components/datetime/utils/data.ts b/core/src/components/datetime/utils/data.ts index 9c6752fde5..6de3aae2a6 100644 --- a/core/src/components/datetime/utils/data.ts +++ b/core/src/components/datetime/utils/data.ts @@ -221,7 +221,7 @@ export const generateTime = ( const convertedHour = refParts.ampm === 'pm' ? (hour + 12) % 24 : hour; return (use24Hour ? hour : convertedHour) <= maxParts.hour!; }); - isPMAllowed = maxParts.hour >= 13; + isPMAllowed = maxParts.hour >= 12; } if (maxParts.minute !== undefined && refParts.hour === maxParts.hour) { // The available minutes should only be filtered when the hour is the same as the max hour. @@ -533,7 +533,7 @@ export const getTimeColumnsData = ( minParts?: DatetimeParts, maxParts?: DatetimeParts, allowedHourValues?: number[], - allowedMinuteVaues?: number[] + allowedMinuteValues?: number[] ): { [key: string]: PickerColumnItem[] } => { const use24Hour = is24Hour(locale, hourCycle); const { hours, minutes, am, pm } = generateTime( @@ -542,7 +542,7 @@ export const getTimeColumnsData = ( minParts, maxParts, allowedHourValues, - allowedMinuteVaues + allowedMinuteValues ); const hoursItems = hours.map((hour) => {