@@ -6,13 +6,16 @@ import {
6
6
get ,
7
7
groupBy ,
8
8
isEmpty ,
9
+ padStart ,
9
10
range ,
10
11
uniq ,
11
12
values ,
12
13
} from 'lodash' ;
13
14
import {
15
+ AcadYear ,
14
16
Day ,
15
17
DayText ,
18
+ LessonTime ,
16
19
LessonType ,
17
20
Module ,
18
21
ModuleCode ,
@@ -24,7 +27,13 @@ import { DisplayText, FreeDayConflict, LessonOption, LessonKey, TimeRange } from
24
27
import { ColorMapping } from 'types/reducers' ;
25
28
import { LessonSlot , OptimiseResponse } from 'apis/optimiser' ;
26
29
import { getModuleTimetable } from './modules' ;
27
- import { convertIndexToTime , convertTimeToIndex , NUM_INTERVALS_PER_HOUR } from './timify' ;
30
+ import {
31
+ convertIndexToTime ,
32
+ convertTimeToIndex ,
33
+ getLessonTimeHours ,
34
+ getLessonTimeMinutes ,
35
+ NUM_INTERVALS_PER_HOUR ,
36
+ } from './timify' ;
28
37
29
38
export function getLessonKey ( moduleCode : ModuleCode , lessonType : LessonType ) : LessonKey {
30
39
return `${ moduleCode } |${ lessonType } ` ;
@@ -34,6 +43,17 @@ export function getDisplayText(moduleCode: ModuleCode, lessonType: LessonType):
34
43
return `${ moduleCode } ${ lessonType } ` ;
35
44
}
36
45
46
+ export function getOptimiserAcadYear ( acadYear : AcadYear ) : string {
47
+ const [ from , to ] = acadYear . split ( '/' ) ;
48
+ return `${ from } -${ to } ` ;
49
+ }
50
+
51
+ export function getOptimiserTime ( time : LessonTime ) : string {
52
+ const hh = padStart ( `${ getLessonTimeHours ( time ) } ` , 2 , '0' ) ;
53
+ const mm = padStart ( `${ getLessonTimeMinutes ( time ) } ` , 2 , '0' ) ;
54
+ return `${ hh } :${ mm } ` ;
55
+ }
56
+
37
57
export function getLessonTypes ( lessons : readonly RawLesson [ ] ) : LessonType [ ] {
38
58
return uniq ( lessons . map ( ( lesson ) => lesson . lessonType ) ) ;
39
59
}
@@ -123,11 +143,11 @@ export function getFreeDayConflicts(
123
143
return isEmpty ( conflictingDays )
124
144
? null
125
145
: {
126
- moduleCode,
127
- lessonType,
128
- displayText,
129
- days : conflictingDays ,
130
- } ;
146
+ moduleCode,
147
+ lessonType,
148
+ displayText,
149
+ days : conflictingDays ,
150
+ } ;
131
151
} ) ,
132
152
) ;
133
153
} ) ;
@@ -153,6 +173,9 @@ export function isSaturdayInOptions(lessonOptions: LessonOption[]): boolean {
153
173
. some ( ( day ) => day === 'Saturday' ) ;
154
174
}
155
175
176
+ // TOOD: check styles
177
+
178
+ // TODO: add unit tests
156
179
export function getTimeValues ( timeRange : TimeRange ) {
157
180
const earliestIndex = convertTimeToIndex ( timeRange . earliest ) ;
158
181
const latestIndex = convertTimeToIndex ( timeRange . latest ) + 1 ;
0 commit comments