@@ -78,26 +78,20 @@ function toDate(parts: DateParts): Date | undefined {
7878 return p ? new Date ( Date . UTC ( p . year , p . month - 1 , p . day ) ) : undefined ;
7979}
8080
81+ function toParts ( date : Date | undefined ) : { year : number ; month : number ; day : number } | null {
82+ return date
83+ ? { year : date . getUTCFullYear ( ) , month : date . getUTCMonth ( ) + 1 , day : date . getUTCDate ( ) }
84+ : null ;
85+ }
86+
87+ // oxlint-disable-next-line max-params
8188function segmentBounds (
8289 type : 'year' | 'month' | 'day' ,
8390 ctx : { year : number ; month : number } ,
84- minDate : Date | undefined ,
85- maxDate : Date | undefined
91+ dateConstraints : { minDate : Date | undefined ; maxDate : Date | undefined } ,
8692) : { min : number ; max : number } {
87- const minP = minDate
88- ? {
89- year : minDate . getUTCFullYear ( ) ,
90- month : minDate . getUTCMonth ( ) + 1 ,
91- day : minDate . getUTCDate ( ) ,
92- }
93- : null ;
94- const maxP = maxDate
95- ? {
96- year : maxDate . getUTCFullYear ( ) ,
97- month : maxDate . getUTCMonth ( ) + 1 ,
98- day : maxDate . getUTCDate ( ) ,
99- }
100- : null ;
93+ const minP = toParts ( dateConstraints . minDate ) ;
94+ const maxP = toParts ( dateConstraints . maxDate ) ;
10195
10296 if ( type === 'year' ) {
10397 return { min : minP ?. year ?? 1 , max : maxP ?. year ?? 9999 } ;
@@ -205,7 +199,7 @@ export class DatePrompt extends Prompt<Date> {
205199 if ( ! segment ) return undefined ;
206200 this . #cursor. positionInSegment = Math . max (
207201 0 ,
208- Math . min ( this . #cursor. positionInSegment , segment . len - 1 )
202+ Math . min ( this . #cursor. positionInSegment , segment . len - 1 ) ,
209203 ) ;
210204 return { segment, index } ;
211205 }
@@ -217,7 +211,7 @@ export class DatePrompt extends Prompt<Date> {
217211 if ( ! ctx ) return ;
218212 this . #cursor. segmentIndex = Math . max (
219213 0 ,
220- Math . min ( this . #segments. length - 1 , ctx . index + direction )
214+ Math . min ( this . #segments. length - 1 , ctx . index + direction ) ,
221215 ) ;
222216 this . #cursor. positionInSegment = 0 ;
223217 this . #segmentSelected = true ;
@@ -230,12 +224,10 @@ export class DatePrompt extends Prompt<Date> {
230224 const raw = this . #segmentValues[ segment . type ] ;
231225 const isBlank = ! raw || raw . replace ( / _ / g, '' ) === '' ;
232226 const num = Number . parseInt ( ( raw || '0' ) . replace ( / _ / g, '0' ) , 10 ) || 0 ;
233- const bounds = segmentBounds (
234- segment . type ,
235- parse ( this . #segmentValues) ,
236- this . #minDate,
237- this . #maxDate
238- ) ;
227+ const bounds = segmentBounds ( segment . type , parse ( this . #segmentValues) , {
228+ minDate : this . #minDate,
229+ maxDate : this . #maxDate,
230+ } ) ;
239231
240232 let next : number ;
241233 if ( isBlank ) {
0 commit comments