From 5925e7608ef04f8877e4dd8a80b2c8bdc1cfd4bd Mon Sep 17 00:00:00 2001 From: Sean Perkins Date: Thu, 20 Jan 2022 12:47:06 -0500 Subject: [PATCH] fix(datetime): datetime locale with h23 will respect max time range (#24610) Resolves #24588 --- .../src/components/datetime/test/data.spec.ts | 30 ++++ .../datetime/test/minmax/index.html | 142 ++++++++---------- core/src/components/datetime/utils/data.ts | 2 +- 3 files changed, 96 insertions(+), 78 deletions(-) diff --git a/core/src/components/datetime/test/data.spec.ts b/core/src/components/datetime/test/data.spec.ts index e557f2c03a..6a577c7db3 100644 --- a/core/src/components/datetime/test/data.spec.ts +++ b/core/src/components/datetime/test/data.spec.ts @@ -257,5 +257,35 @@ describe('generateTime()', () => { expect(minutes.length).toEqual(60); }); }); + + it('should respect the min & max bounds', () => { + const refValue = { + day: undefined, + month: undefined, + year: undefined, + hour: 20, + minute: 30 + } + + const minParts = { + day: undefined, + month: undefined, + year: undefined, + hour: 19, + minute: 30 + } + + const maxParts = { + day: undefined, + month: undefined, + year: undefined, + hour: 20, + minute: 40 + }; + + const { hours } = generateTime(refValue, 'h23', minParts, maxParts); + + expect(hours).toStrictEqual([19, 20]); + }); }) }) diff --git a/core/src/components/datetime/test/minmax/index.html b/core/src/components/datetime/test/minmax/index.html index 3a92d412e6..fbba64a03a 100644 --- a/core/src/components/datetime/test/minmax/index.html +++ b/core/src/components/datetime/test/minmax/index.html @@ -1,89 +1,77 @@ - - - Datetime - Min/Max - - - - - - - - - - - - Datetime - Min/Max - - - -
-
-

Value inside Bounds

- -
-
-

Value Outside Bounds

- -
-
-

AM/PM Min/Max

- -
-
-

h23 Min

- -
+ color: #6f7378; + + margin-top: 10px; + margin-left: 5px; + } + + ion-datetime { + box-shadow: 0px 16px 32px rgba(0, 0, 0, 0.25), 0px 8px 16px rgba(0, 0, 0, 0.25); + border-radius: 8px; + } + + + + + + + + Datetime - Min/Max + + + +
+
+

Value inside Bounds

+
- +
+

Value Outside Bounds

+ +
+
+

AM/PM Min/Max

+ +
+
+

h23 Min

+ +
+
+

locale: en-GB

+ +
+
+
- -
- + + + + diff --git a/core/src/components/datetime/utils/data.ts b/core/src/components/datetime/utils/data.ts index 4630dd1700..5228966bd8 100644 --- a/core/src/components/datetime/utils/data.ts +++ b/core/src/components/datetime/utils/data.ts @@ -219,7 +219,7 @@ export const generateTime = ( if (maxParts.hour !== undefined) { processedHours = processedHours.filter(hour => { const convertedHour = refParts.ampm === 'pm' ? (hour + 12) % 24 : hour; - return convertedHour <= maxParts.hour!; + return (use24Hour ? hour : convertedHour) <= maxParts.hour!; }); isPMAllowed = maxParts.hour >= 13; }