This repository has been archived by the owner on Apr 12, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlessons.js
83 lines (57 loc) · 1.73 KB
/
lessons.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
const lessonPlan = require("./lessonPlan.json");
// Todays classes but not the ones that are already over
function now() {
// Fixing datetime using timezone
let nz_date_string = new Date().toLocaleString("en-US", { timeZone: "Europe/Rome" });
let d = new Date(nz_date_string);
// Today there might be no classes!
if (lessonPlan.lesson_plan[d.getDay()].length == 0)
return [];
// Today's classes
todayAgenda = lessonPlan.lesson_plan[d.getDay()].map(i => {return {
from: i[1],
to: i[2],
courseid: i[0],
course: lessonPlan.lessons[i[0]]
}})
let currentTime = parseInt("".concat(d.getHours(), (d.getMinutes() < 10 ? "0" : ""), d.getMinutes()))
for (var i in todayAgenda) {
if (todayAgenda[i].to < currentTime)
delete todayAgenda[i];
}
return todayAgenda;
}
// Next class coming up
function next() {
// Fixing datetime using timezone
let nz_date_string = new Date().toLocaleString("en-US", { timeZone: "Europe/Rome" });
let d = new Date(nz_date_string);
// Looking in the next 5 days
for (var i = 0; i < 5; i++) {
// Increase day
d.setDate(d.getDate() + 1);
if (lessonPlan.lesson_plan[d.getDay()].length == 0)
continue;
return {
deltaDays: i+1,
from: lessonPlan.lesson_plan[d.getDay()][0][1],
to: lessonPlan.lesson_plan[d.getDay()][0][2],
course: lessonPlan.lessons[lessonPlan.lesson_plan[d.getDay()][0][0]]
};
}
// Nothing was found
return {};
}
// [RAW] All classes
function all() {
return lessonPlan.lessons;
}
// [RAW] Complete calendar
function calendar() {
return lessonPlan.lesson_plan;
}
// One class based on id
function one(id) {
return lessonPlan.lessons[id]
}
module.exports = [now, next, all, one, calendar];