Skip to content

Commit c65e5cd

Browse files
committed
feat: date based conflict detection!
1 parent 0c08ded commit c65e5cd

3 files changed

Lines changed: 29 additions & 8 deletions

File tree

logic/classes.ts

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,16 @@
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
}
3738
export 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
}

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
"@nuxtjs/axios": "^5.13.6",
1818
"@nuxtjs/pwa": "^3.3.5",
1919
"core-js": "^3.19.3",
20+
"date-fns": "^2.28.0",
2021
"nuxt": "^2.15.8",
2122
"vue": "^2.6.14",
2223
"vue-server-renderer": "^2.6.14",

yarn.lock

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4101,6 +4101,11 @@ data-urls@^2.0.0:
41014101
whatwg-mimetype "^2.3.0"
41024102
whatwg-url "^8.0.0"
41034103

4104+
date-fns@^2.28.0:
4105+
version "2.28.0"
4106+
resolved "https://registry.yarnpkg.com/date-fns/-/date-fns-2.28.0.tgz#9570d656f5fc13143e50c975a3b6bbeb46cd08b2"
4107+
integrity sha512-8d35hViGYx/QH0icHYCeLmsLmMUheMmTyV9Fcm6gvNwdw31yXXH+O85sOBJ+OLnLQMKZowvpKb6FgMIQjcpvQw==
4108+
41044109
de-indent@^1.0.2:
41054110
version "1.0.2"
41064111
resolved "https://registry.yarnpkg.com/de-indent/-/de-indent-1.0.2.tgz#b2038e846dc33baa5796128d0804b455b8c1e21d"

0 commit comments

Comments
 (0)