Skip to content

Commit

Permalink
clock.js: Fail gracefully when period is missing
Browse files Browse the repository at this point in the history
Until issue Aspine#140 ("Schedule Tab Only Displays First Three Classes") is
fixed, certain periods do not exist in the schedule; the clock code now
fails gracefully in this case.
  • Loading branch information
psvenk committed Oct 26, 2020
1 parent 7a274f6 commit 2a20a69
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions public/js/clock.js
Original file line number Diff line number Diff line change
Expand Up @@ -171,13 +171,16 @@ function get_period_name(default_name) {
period_names.silver.push(currentTableData.schedule.silver[i]);
}
}
// Guess lunch
current_schedule = get_schedule(period_names.black[2].room, period_names.black[2].id);
// Guess lunch if there is a period 3 and we are not following the
// covid schedule
if (!covid_schedule && period_names.black[2]) {
current_schedule = get_schedule(period_names.black[2].room, period_names.black[2].id);
}
}
let bs_day = document.getElementById("schedule_title").innerHTML.toLowerCase();
// period_names has class names now
let index = Number(default_name.charAt(default_name.length - 1)) - 1;
if(isNaN(index)) {
if(isNaN(index) || !period_names[bs_day][index]) {
return default_name;
}
return period_names[bs_day][index].name;
Expand Down

0 comments on commit 2a20a69

Please sign in to comment.