Skip to content

Commit

Permalink
Merge pull request #283 from Aspine/schedule-times
Browse files Browse the repository at this point in the history
Add times to the schedule
  • Loading branch information
jadebuckwalter authored Mar 24, 2021
2 parents 57c7ee1 + e4b3dd9 commit d45b3c1
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
17 changes: 16 additions & 1 deletion public/js/clock.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,16 @@ function schedulesCallback(response) {
redraw_clock_with_timestamp();
}

// Takes a time from schedule.json and formats it as a string
function formatTime(time) {
const hours = Math.floor(time / 1000 / 60 / 60);
const minutes = time / 1000 / 60 % 60;
return new Date(2000, 1, 1, hours, minutes).toLocaleTimeString([], {
hour: "numeric",
minute: "numeric",
});
}

function update_formattedSchedule() {
if (selected_day_of_week < 0) {
const now = date_override ? new Date(date_override) : new Date();
Expand All @@ -53,7 +63,7 @@ function update_formattedSchedule() {
const bs_day = [1, 4].includes(day_of_week) ? "silver" : "black";

currentTableData.formattedSchedule = schedules[current_schedule]
.map(({ name }, i) => {
.map(({ name, start, end }, i) => {
let room = "";
let class_name = get_period_name(name, day_of_week);
for (entry of currentTableData.schedule[bs_day]) {
Expand All @@ -64,6 +74,10 @@ function update_formattedSchedule() {
}
}

let time = formatTime(start);
if (name !== "After School")
time += "–" + formatTime(end);

// The index (1 to 8) of the color to use for this class
const color_number = i < 8 ? i + 1 : 8;
let color;
Expand All @@ -76,6 +90,7 @@ function update_formattedSchedule() {
return {
period: name,
room: room,
time: time,
class: class_name,
color: color,
};
Expand Down
7 changes: 7 additions & 0 deletions public/js/home.js
Original file line number Diff line number Diff line change
Expand Up @@ -604,6 +604,12 @@ let scheduleTable = new Tabulator("#scheduleTable", {
headerSort: false,
formatter: "html",
},
{
title: "Time",
field: "time",
width: 150,
headerSort: false,
},
{
title: "Room",
field: "room",
Expand All @@ -613,6 +619,7 @@ let scheduleTable = new Tabulator("#scheduleTable", {
{
title: "Class",
field: "class",
width: 400,
headerSort: false,
formatter: "html",
},
Expand Down

0 comments on commit d45b3c1

Please sign in to comment.