@@ -39,6 +39,9 @@ export interface MatTimepickerOption<D = unknown> {
39
39
40
40
/** Label to show to the user. */
41
41
label : string ;
42
+
43
+ /** Whether the option is disabled. */
44
+ disabled ?: boolean ;
42
45
}
43
46
44
47
/** Parses an interval value into seconds. */
@@ -88,17 +91,39 @@ export function generateOptions<D>(
88
91
min : D ,
89
92
max : D ,
90
93
interval : number ,
94
+ shouldDisplayUnavailableItems : boolean = false ,
91
95
) : MatTimepickerOption < D > [ ] {
92
96
const options : MatTimepickerOption < D > [ ] = [ ] ;
93
- let current = adapter . compareTime ( min , max ) < 1 ? min : max ;
94
97
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
+ }
102
127
}
103
128
104
129
return options ;
0 commit comments