Skip to content

Commit 526e411

Browse files
authoredNov 8, 2022
fix(datetime): min/max correctly display available day periods (#26241)
Resolves #26216
1 parent 57105d5 commit 526e411

File tree

2 files changed

+33
-3
lines changed

2 files changed

+33
-3
lines changed
 

‎core/src/components/datetime/test/data.spec.ts

+30
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,36 @@ describe('generateTime()', () => {
205205
expect(minutes).toStrictEqual([10, 15, 20]);
206206
});
207207

208+
it('should allow both am/pm when min is am and max is pm', () => {
209+
// https://github.com/ionic-team/ionic-framework/issues/26216
210+
const today = {
211+
day: 22,
212+
month: 5,
213+
year: 2021,
214+
hour: 5,
215+
minute: 43,
216+
};
217+
const min = {
218+
day: 22,
219+
month: 5,
220+
year: 2021,
221+
hour: 11,
222+
minute: 14,
223+
};
224+
const max = {
225+
day: 22,
226+
month: 5,
227+
year: 2021,
228+
hour: 12,
229+
minute: 14,
230+
};
231+
232+
const { am, pm } = generateTime(today, 'h12', min, max);
233+
234+
expect(am).toBe(true);
235+
expect(pm).toBe(true);
236+
});
237+
208238
describe('hourCycle is 23', () => {
209239
it('should return hours in 24 hour format', () => {
210240
const refValue = {

‎core/src/components/datetime/utils/data.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,7 @@ export const generateTime = (
221221
const convertedHour = refParts.ampm === 'pm' ? (hour + 12) % 24 : hour;
222222
return (use24Hour ? hour : convertedHour) <= maxParts.hour!;
223223
});
224-
isPMAllowed = maxParts.hour >= 13;
224+
isPMAllowed = maxParts.hour >= 12;
225225
}
226226
if (maxParts.minute !== undefined && refParts.hour === maxParts.hour) {
227227
// The available minutes should only be filtered when the hour is the same as the max hour.
@@ -533,7 +533,7 @@ export const getTimeColumnsData = (
533533
minParts?: DatetimeParts,
534534
maxParts?: DatetimeParts,
535535
allowedHourValues?: number[],
536-
allowedMinuteVaues?: number[]
536+
allowedMinuteValues?: number[]
537537
): { [key: string]: PickerColumnItem[] } => {
538538
const use24Hour = is24Hour(locale, hourCycle);
539539
const { hours, minutes, am, pm } = generateTime(
@@ -542,7 +542,7 @@ export const getTimeColumnsData = (
542542
minParts,
543543
maxParts,
544544
allowedHourValues,
545-
allowedMinuteVaues
545+
allowedMinuteValues
546546
);
547547

548548
const hoursItems = hours.map((hour) => {

0 commit comments

Comments
 (0)
Please sign in to comment.