3
3
*/
4
4
5
5
import moment from 'moment' ;
6
- import { sumBy } from 'lodash' ;
6
+ import { find , sumBy } from 'lodash' ;
7
7
8
8
export const SORTS = {
9
9
CURRENT_PHASE : 'current-phase' ,
@@ -25,7 +25,15 @@ export default {
25
25
name : 'Current phase' ,
26
26
} ,
27
27
[ SORTS . MOST_RECENT ] : {
28
- func : ( a , b ) => moment ( b . registrationStartDate ) . diff ( a . registrationStartDate ) ,
28
+ func : ( a , b ) => {
29
+ const getRegistrationStartDate = ( challenge ) => {
30
+ const registrationPhase = find ( challenge . phases , p => p . name === 'Registration' ) ;
31
+ return registrationPhase . actualStartDate || registrationPhase . scheduledStartDate ;
32
+ } ;
33
+ const aRegistrationStartDate = getRegistrationStartDate ( a ) ;
34
+ const bRegistrationStartDate = getRegistrationStartDate ( b ) ;
35
+ return moment ( bRegistrationStartDate ) . diff ( aRegistrationStartDate ) ;
36
+ } ,
29
37
name : 'Most recent' ,
30
38
} ,
31
39
[ SORTS . NUM_REGISTRANTS ] : {
@@ -42,8 +50,13 @@ export default {
42
50
} ,
43
51
[ SORTS . TIME_TO_REGISTER ] : {
44
52
func : ( a , b ) => {
45
- const aDate = moment ( a . registrationEndDate || a . submissionEndTimestamp ) ;
46
- const bDate = moment ( b . registrationEndDate || b . submissionEndTimestamp ) ;
53
+ const getRegistrationEndDate = ( challenge ) => {
54
+ const registrationPhase = find ( challenge . phases , p => p . name === 'Registration' ) ;
55
+ return registrationPhase . actualEndDate || registrationPhase . scheduledEndDate ;
56
+ } ;
57
+
58
+ const aDate = moment ( getRegistrationEndDate ( a ) || a . submissionEndTimestamp ) ;
59
+ const bDate = moment ( getRegistrationEndDate ( b ) || b . submissionEndTimestamp ) ;
47
60
48
61
if ( aDate . isBefore ( ) && bDate . isAfter ( ) ) return 1 ;
49
62
if ( aDate . isAfter ( ) && bDate . isBefore ( ) ) return - 1 ;
0 commit comments