11import { Activity , Assignment , Competition , Person } from '@wca/helpers' ;
22import { getWorldAssignmentsExtension } from '@/extensions/com.competitiongroups.worldsassignments' ;
33import i18n from '@/i18n' ;
4- import { getAllActivities , getRooms } from '@/lib/activities' ;
4+ import { getAllActivities } from '@/lib/activities' ;
55import { isUnofficialParsedActivityCode , parseActivityCodeFlexible } from '@/lib/activityCodes' ;
66import { eventById , isOfficialEventId } from '@/lib/events' ;
77import { formatNumericDate , getNumericDateFormatter } from '@/lib/time' ;
88import { byDate } from '@/lib/utils' ;
99
10+ type ActivityWithLocation = Activity & {
11+ room ?: { id : number } ;
12+ parent ?: { room ?: { id : number } } ;
13+ } ;
14+
15+ const getActivityTimeZone = (
16+ venues : Competition [ 'schedule' ] [ 'venues' ] ,
17+ activity : ActivityWithLocation ,
18+ ) => {
19+ const roomId = activity . room ?. id ?? activity . parent ?. room ?. id ;
20+ const venue = venues . find ( ( candidate ) => candidate . rooms . some ( ( room ) => room . id === roomId ) ) ;
21+
22+ return venue ?. timezone ?? venues [ 0 ] ?. timezone ;
23+ } ;
24+
1025export const getNormalAssignments = ( wcif : Competition , person : Person ) => {
1126 const allActivities = getAllActivities ( wcif ) ;
1227
@@ -105,20 +120,24 @@ const getFmcAttemptAssignments = (wcif: Competition, person: Person) => {
105120 return parsed . eventId === '333fm' && parsed . attemptNumber !== null ;
106121 } ) ;
107122
108- return fmcAttemptActivities . map (
109- (
110- activity ,
111- ) : Assignment & {
112- type : 'extra' ;
113- activity : Activity ;
114- } => ( {
115- type : 'extra' ,
116- assignmentCode : 'competitor' ,
117- activityId : activity . id ,
118- stationNumber : null ,
119- activity,
120- } ) ,
121- ) ;
123+ const personActivities = person . assignments ?. map ( ( ass ) => ass . activityId ) ;
124+
125+ return fmcAttemptActivities
126+ . filter ( ( activity ) => personActivities ?. includes ( activity . id ) )
127+ . map (
128+ (
129+ activity ,
130+ ) : Assignment & {
131+ type : 'extra' ;
132+ activity : Activity ;
133+ } => ( {
134+ type : 'extra' ,
135+ assignmentCode : 'competitor' ,
136+ activityId : activity . id ,
137+ stationNumber : null ,
138+ activity,
139+ } ) ,
140+ ) ;
122141} ;
123142
124143export const getAllAssignments = ( wcif : Competition , person : Person ) => {
@@ -157,18 +176,14 @@ export const getGroupedAssignmentsByDate = (wcif: Competition, person: Person) =
157176 } ;
158177 }
159178
160- const roomId = a . activity && 'room' in a . activity && a . activity . room ?. id ;
161- const parent = a . activity && 'parent' in a . activity && a . activity . parent ;
162-
163- const venue = venues . find ( ( v ) => v . rooms . some ( ( r ) => r . id === roomId || parent ) ) ;
164-
165179 const dateTime = new Date ( a . activity ?. startTime ) ;
166- const date = formatNumericDate ( dateTime , venue ?. timezone ) ;
180+ const timeZone = getActivityTimeZone ( venues , a . activity ) ;
181+ const date = formatNumericDate ( dateTime , timeZone ) ;
167182
168183 return {
169184 approxDateTime : dateTime . getTime ( ) ,
170185 date : date ,
171- dateParts : getNumericDateFormatter ( venue ?. timezone ) . formatToParts ( dateTime ) ,
186+ dateParts : getNumericDateFormatter ( timeZone ) . formatToParts ( dateTime ) ,
172187 } ;
173188 } )
174189 . filter ( ( v , i , arr ) => arr . findIndex ( ( { date } ) => date === v . date ) === i ) ;
@@ -186,7 +201,6 @@ export const getGroupedAssignmentsByDate = (wcif: Competition, person: Person) =
186201export const getAssignmentsWithParsedDate = ( wcif : Competition , person : Person ) => {
187202 const allAssignments = getAllAssignments ( wcif , person ) ;
188203 const venues = wcif . schedule . venues ;
189- const rooms = getRooms ( wcif ) ;
190204
191205 return allAssignments
192206 . map ( ( assignment ) => {
@@ -200,7 +214,10 @@ export const getAssignmentsWithParsedDate = (wcif: Competition, person: Person)
200214 return {
201215 assignment,
202216 activity,
203- date : formatNumericDate ( new Date ( activity . startTime ) , venues [ 0 ] . timezone ) ,
217+ date : formatNumericDate (
218+ new Date ( activity . startTime ) ,
219+ getActivityTimeZone ( venues , activity ) ,
220+ ) ,
204221 } ;
205222 }
206223
@@ -212,16 +229,12 @@ export const getAssignmentsWithParsedDate = (wcif: Competition, person: Person)
212229 } ;
213230 }
214231
215- const roomId = ( activity . room || activity . parent ?. room ) ?. id ;
216-
217- const venue = activity ?. room ?. id ? rooms . find ( ( r ) => r . id === roomId ) ?. venue : venues [ 0 ] ;
218-
219232 const dateTime = new Date ( activity . startTime ) ;
220233
221234 return {
222235 assignment,
223236 activity,
224- date : formatNumericDate ( dateTime , venue ?. timezone ) ,
237+ date : formatNumericDate ( dateTime , getActivityTimeZone ( venues , activity ) ) ,
225238 } ;
226239 }
227240 } )
0 commit comments