@@ -95,7 +95,7 @@ const displayDates = () => {
95
95
96
96
for ( let i = 0 ; i <= lastOfPrevMonth . getDay ( ) ; i ++ ) {
97
97
const text = lastOfPrevMonth . getDate ( ) - lastOfPrevMonth . getDay ( ) + i ;
98
- const button = createButton ( text , true ) ;
98
+ const button = createButton ( text , true , - 1 ) ;
99
99
dates . appendChild ( button ) ;
100
100
}
101
101
@@ -117,25 +117,25 @@ const displayDates = () => {
117
117
for ( let i = firstOfNextMonth . getDay ( ) ; i < 7 ; i ++ ) {
118
118
const text = firstOfNextMonth . getDate ( ) - firstOfNextMonth . getDay ( ) + i ;
119
119
120
- const button = createButton ( text , true ) ;
120
+ const button = createButton ( text , true , 1 ) ;
121
121
dates . appendChild ( button ) ;
122
122
}
123
123
} ;
124
124
125
- const createButton = ( text , isDisabled = false ) => {
125
+ const createButton = ( text , isDisabled = false , type = 0 ) => {
126
126
const currentDate = new Date ( ) ;
127
127
128
+ // determine the date to compare based on the button type
129
+ let comparisonDate = new Date ( year , month + type , text ) ;
130
+
128
131
// check if the current button is the date today
129
132
const isToday =
130
133
currentDate . getDate ( ) === text &&
131
134
currentDate . getFullYear ( ) === year &&
132
135
currentDate . getMonth ( ) === month ;
133
136
134
137
// check if the current button is selected
135
- const selected =
136
- selectedDate . getDate ( ) === text &&
137
- selectedDate . getFullYear ( ) === year &&
138
- selectedDate . getMonth ( ) === month ;
138
+ const selected = selectedDate . getTime ( ) === comparisonDate . getTime ( ) ;
139
139
140
140
const button = document . createElement ( "button" ) ;
141
141
button . textContent = text ;
0 commit comments