1+ import { areIntervalsOverlapping } from 'date-fns'
12// too lazy to add types ;)
2- export function buttonOptions ( todo : any ) {
3+ export function buttonOptions ( checkClass : any ) {
34 let tooltips : String [ ] = [ ]
45 let color = 'grey'
56 let icon = 'mdi-plus'
67 let disabled = false
78
8- let sameCourse = todo . conflicts . sameCourse
9+ let sameCourse = checkClass . conflicts . sameCourse
910 // course already added
1011 if ( sameCourse ) {
1112 // same class
12- if ( sameCourse . crn == todo . crn ) {
13+ if ( sameCourse . crn == checkClass . crn ) {
1314 icon = 'mdi-check'
1415 tooltips = [ 'Remove' ]
1516 color = 'success'
@@ -19,9 +20,9 @@ export function buttonOptions(todo: any) {
1920 icon = 'mdi-plus'
2021 }
2122 }
22- if ( todo . conflicts . _any ) {
23+ if ( checkClass . conflicts . _any ) {
2324 icon = 'mdi-alert-circle'
24- tooltips = todo . conflicts . time . map ( ( c : any ) => 'Conflict: ' + c . name )
25+ tooltips = checkClass . conflicts . time . map ( ( c : any ) => 'Conflict: ' + c . name )
2526 color = 'error'
2627 disabled = true
2728 }
@@ -32,7 +33,7 @@ export function buttonOptions(todo: any) {
3233 color,
3334 tooltips,
3435 }
35- return { ...todo , buttonOptions }
36+ return { ...checkClass , buttonOptions }
3637}
3738export function findConflicts ( checkClass : any , selectedClasses : any [ ] ) {
3839 // same course
@@ -62,6 +63,20 @@ export function findConflicts(checkClass: any, selectedClasses: any[]) {
6263 return { ...checkClass , conflicts }
6364}
6465
65- function checkConflict ( c1 : any , c2 : any ) : boolean {
66- return JSON . stringify ( c1 . days ) == JSON . stringify ( c2 . days )
66+ function checkConflict ( c1s : any , c2s : any ) : boolean {
67+ let intersection = c1s . days . filter ( ( dayc1 : any ) => c2s . days . includes ( dayc1 ) )
68+ if ( intersection . length > 0 ) {
69+ let c1time = c1s . time . split ( '-' )
70+ let c2time = c2s . time . split ( '-' )
71+ let c1t1 : number = parseInt ( c1time [ 0 ] )
72+ let c1t2 : number = parseInt ( c1time [ 1 ] )
73+ let c2t1 : number = parseInt ( c2time [ 0 ] )
74+ let c2t2 : number = parseInt ( c2time [ 1 ] )
75+
76+ return areIntervalsOverlapping (
77+ { start : new Date ( c1t1 ) , end : new Date ( c1t2 ) } ,
78+ { start : new Date ( c2t1 ) , end : new Date ( c2t2 ) }
79+ )
80+ }
81+ return false
6782}
0 commit comments