-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathparse.js
143 lines (117 loc) · 3.9 KB
/
parse.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
var fs = require('fs');
const schedule = require('./public/schedule.json');
const cecsLabs = ["ECS-405", "ECS-413", "ECS-414", "ECS-407", "ECS-411", "ECS-412", "ECS-416", "ECS-403", "ECS-404", "ECS-305"];
/**
* Time object for tuple of start and end time in minutes
*/
class Time {
#start;
#end;
constructor(start, end) {
this.#start = start;
this.#end = end;
this.time = [this.#start, this.#end];
}
get start() {
return this.#start;
}
get end() {
return this.#end;
}
get time() {
return this.time;
}
}
/**
*
* @param {*} hours String of hours
* @param {*} minutes String of minutes
* @returns INTEGER the time of the day in minutes
*/
function toMinutes(hours, minutes){
return ((Number(hours) * 60) + Number(minutes));
}
/**
*
* @param {*} time String time
* @returns start and end time in minutes
*/
function parseTimeString(time) {
if (time.includes("AM")) {
var splitTimes = time.split("-");
var startTime = splitTimes[0].split(":");
var startTimeMinutes = toMinutes(startTime[0], startTime[1]);
var endTime = time.substring(0, time[1].indexOf("AM"));
var endTimeSplit = endTime.split(":");
var endTimeMinutes = toMinutes(endTimeSplit[0], endTimeSplit[1]);
const result = new Time(startTimeMinutes, endTimeMinutes);
return result;
}
else if (time.includes("PM")) {
var splitTimes = time.split("-");
var startTime = time[0].split(":");
var endTime = time.substring(0, time[1].indexOf("PM"));
var endTimeSplit = endTime.split(":");
var endTimeMinutes = toMinutes(endTimeSplit[0], endTimeSplit[1]);
const result = new Time(startTimeMinutes, endTimeMinutes);
return result;
}
else {
console.log("Time not right format or N/A");
}
return 0;
}
// Class for class objects
class Class {
// #height = 0;
// #width;
#sunday = new Array(); //0
#monday = new Array(); //1
#tuesday = new Array(); // 2
#wednesday = new Array(); // 3
#thursday = new Array(); // 4
#friday = new Array(); //5
#saturday = new Array(); // 6
#week = [this.#sunday, this.#monday, this.#tuesday, this.#wednesday, this.#thursday, this.#friday, this.#saturday];
#startTime = new Date();
#endTime = new Date();
/**
*
* @param {*} classroom the classroom name and number
* @param {*} days String of days that the class is on ("MW", "TuTh", "F", "Sa", "M", "W", "Tu", "Th")
* @param {*} times String of the time duration of the class. "8-9:15AM" or "5:30-6:45pm"
*/
constructor(classroom, days, times){
this.classroom = classroom;
}
}
for (let i = 0; i < schedule.childCount; i++){
if (schedule.children[i].role.toString() == "table"){
for (let j = 1; j < schedule.children[i].childCount; j++){
if (cecsLabs.includes(schedule.children[i].children[j].children[9].children[0].name.toString())) {
console.log(schedule.children[i].children[j].children[6].children[0].name); // Days String
console.log(schedule.children[i].children[j].children[7].children[0].name); // Time String
console.log(schedule.children[i].children[j].children[9].children[0].name); // Room Number
}
}
}
}
// const numm = new Date(Date.now());
// console.log(numm.getDay());
/**
* new Date(year, monthIndex, day, hours, minutes, seconds)
* new Date(dateString)
* date.getDay(): returns the day of the week (0-6)
* M-Th = 1-4
*
*/
// var testing = "8-10:30AM";
// console.log(testing.split("-"));
/**
* Start: Enter specific time. Thu 2 pm. find the room with the most time.
* steps could be:
* check if the class is open at that specific time
*
* Return the open lab rooms in order of time remaining
*/
// console.log(Date.parse("8-10:30AM"));