1
- import { AssignmentDTO } from "../../IsaacApiTypes" ;
1
+ import { AssignmentDTO , IAssignmentLike } from "../../IsaacApiTypes" ;
2
2
import orderBy from "lodash/orderBy" ;
3
3
import { EnhancedAssignment } from "../../IsaacAppTypes" ;
4
4
import { API_PATH , extractTeacherName , matchesAllWordsInAnyOrder } from "./" ;
@@ -15,13 +15,13 @@ function createAssignmentWithStartDate(assignment: AssignmentDTO): AssignmentDTO
15
15
return { ...assignment , startDate : assignmentStartDate } ;
16
16
}
17
17
18
+ const now = new Date ( ) ;
19
+ const midnightLastNight = new Date ( now ) ;
20
+ midnightLastNight . setHours ( 0 , 0 , 0 , 0 ) ;
21
+
18
22
type AssignmentStatus = "inProgressRecent" | "inProgressOld" | "allAttempted" | "allCorrect" ;
19
23
export const filterAssignmentsByStatus = ( assignments : AssignmentDTO [ ] | undefined | null ) => {
20
- const now = new Date ( ) ;
21
24
const fourWeeksAgo = new Date ( now . valueOf ( ) - ( 4 * 7 * 24 * 60 * 60 * 1000 ) ) ;
22
- // Midnight last night:
23
- const midnightLastNight = new Date ( now ) ;
24
- midnightLastNight . setHours ( 0 , 0 , 0 , 0 ) ;
25
25
26
26
const myAssignments : Record < AssignmentStatus , ( AssignmentDTO & { startDate : Date } ) [ ] > = {
27
27
inProgressRecent : [ ] ,
@@ -104,3 +104,5 @@ export const getDistinctAssignmentSetters = (assignments: AssignmentDTO[] | unde
104
104
export const getAssignmentStartDate = ( a : AssignmentDTO ) : number => ( a . scheduledStartDate ?? a . creationDate ?? 0 ) . valueOf ( ) ;
105
105
106
106
export const hasAssignmentStarted = ( a : AssignmentDTO ) : boolean => getAssignmentStartDate ( a ) <= Date . now ( ) ;
107
+
108
+ export const isOverdue = ( a : IAssignmentLike ) => a . dueDate && a . dueDate < midnightLastNight ;
0 commit comments