mirror of
https://github.com/ionic-team/ionic-framework.git
synced 2025-08-18 03:00:58 +08:00
fix(datetime): minutes only filtered when max hour matches current hour (#24710)
Resolves #24702
This commit is contained in:
@ -95,7 +95,7 @@ describe('generateTime()', () => {
|
||||
day: 19,
|
||||
month: 5,
|
||||
year: 2021,
|
||||
hour: 5,
|
||||
hour: 7,
|
||||
minute: 43
|
||||
}
|
||||
const max = {
|
||||
@ -287,5 +287,50 @@ describe('generateTime()', () => {
|
||||
|
||||
expect(hours).toStrictEqual([19, 20]);
|
||||
});
|
||||
|
||||
it('should return the filtered minutes when the max bound is set', () => {
|
||||
const refValue = {
|
||||
day: undefined,
|
||||
month: undefined,
|
||||
year: undefined,
|
||||
hour: 13,
|
||||
minute: 0
|
||||
};
|
||||
|
||||
const maxParts = {
|
||||
day: undefined,
|
||||
month: undefined,
|
||||
year: undefined,
|
||||
hour: 13,
|
||||
minute: 2
|
||||
};
|
||||
|
||||
const { minutes } = generateTime(refValue, 'h23', undefined, maxParts);
|
||||
|
||||
expect(minutes).toStrictEqual([0, 1, 2]);
|
||||
});
|
||||
|
||||
it('should not filter minutes when the current hour is less than the max hour bound', () => {
|
||||
const refValue = {
|
||||
day: undefined,
|
||||
month: undefined,
|
||||
year: undefined,
|
||||
hour: 12,
|
||||
minute: 0
|
||||
};
|
||||
|
||||
const maxParts = {
|
||||
day: undefined,
|
||||
month: undefined,
|
||||
year: undefined,
|
||||
hour: 13,
|
||||
minute: 2
|
||||
};
|
||||
|
||||
const { minutes } = generateTime(refValue, 'h23', undefined, maxParts);
|
||||
|
||||
expect(minutes.length).toEqual(60);
|
||||
});
|
||||
|
||||
})
|
||||
})
|
||||
|
@ -223,7 +223,11 @@ export const generateTime = (
|
||||
});
|
||||
isPMAllowed = maxParts.hour >= 13;
|
||||
}
|
||||
if (maxParts.minute !== undefined) {
|
||||
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.
|
||||
// For example if the max hour is 10:30 and the current hour is 10:00,
|
||||
// users should be able to select 00-30 minutes.
|
||||
// If the current hour is 09:00, users should be able to select 00-60 minutes.
|
||||
processedMinutes = processedMinutes.filter(minute => minute <= maxParts.minute!);
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user