@@ -39,6 +39,9 @@ export interface MatTimepickerOption<D = unknown> {
3939
4040 /** Label to show to the user. */
4141 label : string ;
42+
43+ /** Whether the option is disabled. */
44+ disabled ?: boolean ;
4245}
4346
4447/** Parses an interval value into seconds. */
@@ -88,17 +91,39 @@ export function generateOptions<D>(
8891 min : D ,
8992 max : D ,
9093 interval : number ,
94+ shouldDisplayUnavailableItems : boolean = false ,
9195) : MatTimepickerOption < D > [ ] {
9296 const options : MatTimepickerOption < D > [ ] = [ ] ;
93- let current = adapter . compareTime ( min , max ) < 1 ? min : max ;
9497
95- while (
96- adapter . sameDate ( current , min ) &&
97- adapter . compareTime ( current , max ) < 1 &&
98- adapter . isValid ( current )
99- ) {
100- options . push ( { value : current , label : adapter . format ( current , formats . display . timeOptionLabel ) } ) ;
101- current = adapter . addSeconds ( current , interval ) ;
98+ if ( shouldDisplayUnavailableItems ) {
99+ const todayMin = adapter . setTime ( adapter . today ( ) , 0 , 0 , 0 ) ;
100+ const todayMax = adapter . setTime ( adapter . today ( ) , 23 , 59 , 0 ) ;
101+ let current = todayMin ;
102+ while (
103+ adapter . sameDate ( current , todayMin ) &&
104+ adapter . compareTime ( current , todayMax ) < 1 &&
105+ adapter . isValid ( current )
106+ ) {
107+ options . push ( {
108+ value : current ,
109+ label : adapter . format ( current , formats . display . timeOptionLabel ) ,
110+ disabled : adapter . compareTime ( current , min ) < 0 || adapter . compareTime ( current , max ) > 0 ,
111+ } ) ;
112+ current = adapter . addSeconds ( current , interval ) ;
113+ }
114+ } else {
115+ let current = adapter . compareTime ( min , max ) < 1 ? min : max ;
116+ while (
117+ adapter . sameDate ( current , min ) &&
118+ adapter . compareTime ( current , max ) < 1 &&
119+ adapter . isValid ( current )
120+ ) {
121+ options . push ( {
122+ value : current ,
123+ label : adapter . format ( current , formats . display . timeOptionLabel ) ,
124+ } ) ;
125+ current = adapter . addSeconds ( current , interval ) ;
126+ }
102127 }
103128
104129 return options ;
0 commit comments