mirror of
https://github.com/ionic-team/ionic-framework.git
synced 2026-03-13 10:22:08 +08:00
fix(datetime): min/max correctly display available day periods (#26241)
Resolves #26216
This commit is contained in:
@@ -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 = {
|
||||
|
||||
@@ -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) => {
|
||||
|
||||
Reference in New Issue
Block a user