@@ -24,6 +24,24 @@ const genericSort = (list, key, ascending, customOrder) => {
24
24
return sorted
25
25
}
26
26
27
+ const durationSort = ( list , ascending ) => {
28
+ const parseDuration = ( duration ) => {
29
+ if ( duration . includes ( ':' ) ) {
30
+ // If it's in the format "HH:mm:ss"
31
+ const [ hours , minutes , seconds ] = duration . split ( ':' ) . map ( Number )
32
+ return ( hours * 3600 + minutes * 60 + seconds ) * 1000
33
+ } else {
34
+ // If it's in the format "nnn ms"
35
+ return parseInt ( duration )
36
+ }
37
+ }
38
+ const sorted = list . sort ( ( a , b ) => parseDuration ( a [ 'duration' ] ) - parseDuration ( b [ 'duration' ] ) )
39
+ if ( ascending ) {
40
+ sorted . reverse ( )
41
+ }
42
+ return sorted
43
+ }
44
+
27
45
const doInitSort = ( ) => {
28
46
const type = storageModule . getSort ( )
29
47
const ascending = storageModule . getSortDirection ( )
@@ -32,7 +50,18 @@ const doInitSort = () => {
32
50
if ( type ?. toLowerCase ( ) === 'original' ) {
33
51
manager . setRender ( list )
34
52
} else {
35
- const sortedList = genericSort ( list , type , ascending , initialOrder )
53
+ let sortedList
54
+ switch ( type ) {
55
+ case 'duration' :
56
+ sortedList = durationSort ( list , ascending )
57
+ break
58
+ case 'result' :
59
+ sortedList = genericSort ( list , type , ascending , initialOrder )
60
+ break
61
+ default :
62
+ sortedList = genericSort ( list , type , ascending )
63
+ break
64
+ }
36
65
manager . setRender ( sortedList )
37
66
}
38
67
}
@@ -45,7 +74,7 @@ const doSort = (type) => {
45
74
storageModule . setSortDirection ( ascending )
46
75
const list = manager . testSubset
47
76
48
- const sortedList = genericSort ( list , type , ascending )
77
+ const sortedList = type === 'duration' ? durationSort ( list , ascending ) : genericSort ( list , type , ascending )
49
78
manager . setRender ( sortedList )
50
79
}
51
80
0 commit comments