@@ -149,7 +149,7 @@ const Days: React.FC<Props> = ({
149
149
) ;
150
150
151
151
const isDateTooEarly = useCallback (
152
- ( day : number , type : string ) => {
152
+ ( day : number , type : "current" | "previous" | "next" ) => {
153
153
if ( ! minDate ) {
154
154
return false ;
155
155
}
@@ -159,18 +159,16 @@ const Days: React.FC<Props> = ({
159
159
next : nextMonth ( calendarData . date )
160
160
} ;
161
161
const newDate = object [ type as keyof typeof object ] ;
162
- const formattedDate = `${ newDate . year ( ) } -${ newDate . month ( ) + 1 } -${
163
- day >= 10 ? day : "0" + day
164
- } `;
165
- return dayjs ( formattedDate ) . isSame ( dayjs ( minDate ) )
162
+ const formattedDate = newDate . set ( "date" , day ) ;
163
+ return dayjs ( formattedDate ) . isSame ( dayjs ( minDate ) , "day" )
166
164
? false
167
165
: dayjs ( formattedDate ) . isBefore ( dayjs ( minDate ) ) ;
168
166
} ,
169
167
[ calendarData . date , minDate ]
170
168
) ;
171
169
172
170
const isDateTooLate = useCallback (
173
- ( day : number , type : string ) => {
171
+ ( day : number , type : "current" | "previous" | "next" ) => {
174
172
if ( ! maxDate ) {
175
173
return false ;
176
174
}
@@ -180,18 +178,16 @@ const Days: React.FC<Props> = ({
180
178
next : nextMonth ( calendarData . date )
181
179
} ;
182
180
const newDate = object [ type as keyof typeof object ] ;
183
- const formattedDate = `${ newDate . year ( ) } -${ newDate . month ( ) + 1 } -${
184
- day >= 10 ? day : "0" + day
185
- } `;
186
- return dayjs ( formattedDate ) . isSame ( maxDate )
181
+ const formattedDate = newDate . set ( "date" , day ) ;
182
+ return dayjs ( formattedDate ) . isSame ( dayjs ( maxDate ) , "day" )
187
183
? false
188
184
: dayjs ( formattedDate ) . isAfter ( dayjs ( maxDate ) ) ;
189
185
} ,
190
186
[ calendarData . date , maxDate ]
191
187
) ;
192
188
193
189
const isDateDisabled = useCallback (
194
- ( day : number , type : string ) => {
190
+ ( day : number , type : "current" | "previous" | "next" ) => {
195
191
if ( isDateTooEarly ( day , type ) || isDateTooLate ( day , type ) ) {
196
192
return true ;
197
193
}
@@ -230,7 +226,7 @@ const Days: React.FC<Props> = ({
230
226
) ;
231
227
232
228
const buttonClass = useCallback (
233
- ( day : number , type : string ) => {
229
+ ( day : number , type : "current" | "previous" | "next" ) => {
234
230
const baseClass = "flex items-center justify-center w-12 h-12 lg:w-10 lg:h-10" ;
235
231
return cn (
236
232
baseClass ,
0 commit comments