File tree Expand file tree Collapse file tree 2 files changed +51
-2
lines changed
core/src/components/datetime Expand file tree Collapse file tree 2 files changed +51
-2
lines changed Original file line number Diff line number Diff line change @@ -95,7 +95,7 @@ describe('generateTime()', () => {
9595 day : 19 ,
9696 month : 5 ,
9797 year : 2021 ,
98- hour : 5 ,
98+ hour : 7 ,
9999 minute : 43
100100 }
101101 const max = {
@@ -287,5 +287,50 @@ describe('generateTime()', () => {
287287
288288 expect ( hours ) . toStrictEqual ( [ 19 , 20 ] ) ;
289289 } ) ;
290+
291+ it ( 'should return the filtered minutes when the max bound is set' , ( ) => {
292+ const refValue = {
293+ day : undefined ,
294+ month : undefined ,
295+ year : undefined ,
296+ hour : 13 ,
297+ minute : 0
298+ } ;
299+
300+ const maxParts = {
301+ day : undefined ,
302+ month : undefined ,
303+ year : undefined ,
304+ hour : 13 ,
305+ minute : 2
306+ } ;
307+
308+ const { minutes } = generateTime ( refValue , 'h23' , undefined , maxParts ) ;
309+
310+ expect ( minutes ) . toStrictEqual ( [ 0 , 1 , 2 ] ) ;
311+ } ) ;
312+
313+ it ( 'should not filter minutes when the current hour is less than the max hour bound' , ( ) => {
314+ const refValue = {
315+ day : undefined ,
316+ month : undefined ,
317+ year : undefined ,
318+ hour : 12 ,
319+ minute : 0
320+ } ;
321+
322+ const maxParts = {
323+ day : undefined ,
324+ month : undefined ,
325+ year : undefined ,
326+ hour : 13 ,
327+ minute : 2
328+ } ;
329+
330+ const { minutes } = generateTime ( refValue , 'h23' , undefined , maxParts ) ;
331+
332+ expect ( minutes . length ) . toEqual ( 60 ) ;
333+ } ) ;
334+
290335 } )
291336} )
Original file line number Diff line number Diff line change @@ -223,7 +223,11 @@ export const generateTime = (
223223 } ) ;
224224 isPMAllowed = maxParts . hour >= 13 ;
225225 }
226- if ( maxParts . minute !== undefined ) {
226+ if ( maxParts . minute !== undefined && refParts . hour === maxParts . hour ) {
227+ // The available minutes should only be filtered when the hour is the same as the max hour.
228+ // For example if the max hour is 10:30 and the current hour is 10:00,
229+ // users should be able to select 00-30 minutes.
230+ // If the current hour is 09:00, users should be able to select 00-60 minutes.
227231 processedMinutes = processedMinutes . filter ( minute => minute <= maxParts . minute ! ) ;
228232 }
229233
You can’t perform that action at this time.
0 commit comments