File tree Expand file tree Collapse file tree
PoliticianPage/ElectionInfo Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -45,7 +45,17 @@ export function PoliticianEmbed({
4545 const biographySource = politician ?. biographySource ;
4646 const officeTitle = `${ politician ?. currentOffice ?. title } - ${ politician ?. currentOffice ?. subtitleShort } ` ;
4747 const upcomingRace = politician ?. upcomingRace ;
48- const isPastElection = new Date ( upcomingRace ?. electionDate ) < new Date ( ) ;
48+ // Compare calendar dates so election day still shows "Running For" (avoids UTC midnight vs local time)
49+ const electionDateStr = upcomingRace ?. electionDate
50+ ? ( typeof upcomingRace . electionDate === "string"
51+ ? upcomingRace . electionDate
52+ : new Date ( upcomingRace . electionDate ) . toISOString ( )
53+ ) . slice ( 0 , 10 )
54+ : "" ;
55+ const today = new Date ( ) ;
56+ const todayStr = `${ today . getFullYear ( ) } -${ String ( today . getMonth ( ) + 1 ) . padStart ( 2 , "0" ) } -${ String ( today . getDate ( ) ) . padStart ( 2 , "0" ) } ` ;
57+ const isPastElection =
58+ electionDateStr !== "" && electionDateStr < todayStr ;
4959
5060 if ( isLoading ) return < LoaderFlag /> ;
5161 if ( error ) return < div > Something went wrong loading this politician.</ div > ;
Original file line number Diff line number Diff line change @@ -41,13 +41,23 @@ function ElectionInfoSection() {
4141 } ) ;
4242 const politicianId = data ?. politicianBySlug ?. id ;
4343 const upcomingRace = data ?. politicianBySlug ?. upcomingRace ;
44- const isPastElection = new Date ( upcomingRace ?. electionDate ) < new Date ( ) ;
44+ // Compare calendar dates so election day still shows "Next Election" (avoids UTC midnight vs local time)
45+ const electionDateStr = upcomingRace ?. electionDate
46+ ? ( typeof upcomingRace . electionDate === "string"
47+ ? upcomingRace . electionDate
48+ : new Date ( upcomingRace . electionDate ) . toISOString ( )
49+ ) . slice ( 0 , 10 )
50+ : "" ;
51+ const today = new Date ( ) ;
52+ const todayStr = `${ today . getFullYear ( ) } -${ String ( today . getMonth ( ) + 1 ) . padStart ( 2 , "0" ) } -${ String ( today . getDate ( ) ) . padStart ( 2 , "0" ) } ` ;
53+ const isPastElection =
54+ electionDateStr !== "" && electionDateStr < todayStr ;
4555
4656 if ( isLoading ) return < LoaderFlag /> ;
4757
4858 const opponents =
4959 upcomingRace ?. candidates ?. filter (
50- ( candidate ) => candidate . id != politicianId
60+ ( candidate ) => candidate . id != politicianId ,
5161 ) || [ ] ;
5262 if ( ! upcomingRace ) return null ;
5363
You can’t perform that action at this time.
0 commit comments