Skip to content

Commit bf43eb8

Browse files
PROD-2066 #comment fix comments #time 5m
1 parent 4d26e6f commit bf43eb8

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

src-ts/lib/work-provider/work-functions/work-factory/work.factory.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -75,17 +75,20 @@ function findMetadata(challenge: Challenge, metadataName: ChallengeMetadataName)
7575

7676
function findOpenPhase(challenge: Challenge): ChallengePhase | undefined {
7777

78+
// sort the phases descending by start date
79+
const sortedPhases: Array<ChallengePhase> = challenge.phases
80+
.sort((a, b) => new Date(b.actualStartDate).getTime() - new Date(a.actualStartDate).getTime())
81+
7882
const now: Date = new Date()
7983
// if we have an open phase, just use that
80-
const openPhase: ChallengePhase | undefined = challenge.phases.find(phase => phase.isOpen)
84+
const openPhase: ChallengePhase | undefined = sortedPhases.find(phase => phase.isOpen)
8185
// otherwise, find the phase that _should_ be open now based on its start/end datetimes
82-
|| challenge.phases
86+
|| sortedPhases
8387
.find(phase => {
8488
return new Date(phase.actualEndDate) > now && new Date(phase.actualStartDate) < now
8589
})
8690
// otherwise, find the most recently started phase that's in the past
87-
|| challenge.phases
88-
.sort((a, b) => new Date(b.actualStartDate).getTime() - new Date(a.actualStartDate).getTime())
91+
|| sortedPhases
8992
.find(phase => {
9093
return new Date(phase.actualStartDate) < now
9194
})

0 commit comments

Comments
 (0)