11import { Competition } from '@wca/helpers' ;
2- import { intlFormat } from 'date-fns ' ;
2+ import { useMemo } from 'react ' ;
33import { useSelector } from 'react-redux' ;
44import { Card , CardContent , Typography } from '@mui/material' ;
55import { shortEventNameById } from '../lib/events' ;
66import { acceptedRegistrations } from '../lib/persons' ;
7- import { pluralize } from '../lib/utils' ;
87
98export default function CompetitionSummary ( ) {
109 const wcif = useSelector ( ( state : { wcif : Competition } ) => state . wcif ) ;
1110 const approvedRegistrations = acceptedRegistrations ( wcif . persons ) ;
1211
13- const formattedDate = intlFormat ( new Date ( wcif . schedule . startDate ) , {
14- weekday : 'short' ,
15- year : 'numeric' ,
16- month : 'short' ,
17- day : 'numeric' ,
18- } ) ;
12+ const startDate = useMemo ( ( ) => {
13+ const start = new Date ( wcif . schedule . startDate ) ;
14+ start . setHours ( start . getHours ( ) + new Date ( ) . getTimezoneOffset ( ) / 60 ) ;
15+ return start ;
16+ } , [ wcif ] ) ;
17+
18+ const endDate = useMemo ( ( ) => {
19+ if ( wcif . schedule . numberOfDays <= 1 ) return undefined ;
20+
21+ const end = new Date ( wcif . schedule . startDate ) ;
22+ end . setDate ( startDate . getDate ( ) + wcif . schedule . numberOfDays ) ;
23+ return end ;
24+ } , [ startDate , wcif . schedule . numberOfDays , wcif . schedule . startDate ] ) ;
1925
2026 return (
2127 < Card >
@@ -25,15 +31,17 @@ export default function CompetitionSummary() {
2531 </ Typography >
2632 < Typography >
2733 < b > Date: </ b >
28- { formattedDate } ({ pluralize ( wcif . schedule . numberOfDays , 'day' , 'days' ) } )
34+ { startDate . toLocaleDateString ( ) }
35+ { endDate ? ` - ${ endDate . toLocaleDateString ( ) } ` : '' }
2936 </ Typography >
3037 < Typography >
3138 < b > Competitors: </ b >
3239 { approvedRegistrations . length }
3340 </ Typography >
3441 < Typography >
3542 < b > Events: </ b >
36- { wcif . events . map ( ( event ) => shortEventNameById ( event . id ) ) . join ( ', ' ) }
43+ { wcif . events . map ( ( event ) => shortEventNameById ( event . id ) ) . join ( ', ' ) } (
44+ { wcif . events . length } )
3745 </ Typography >
3846 </ CardContent >
3947 </ Card >
0 commit comments