diff --git a/public/js/clock.js b/public/js/clock.js index 4e75c662..f3e57ce5 100755 --- a/public/js/clock.js +++ b/public/js/clock.js @@ -1,4 +1,3 @@ -let current_schedule = "regular"; let schedules, logo; let period_names = {black:[], silver:[]}; @@ -16,6 +15,15 @@ large_ctx.translate(large_radius, large_radius); logo = document.getElementById("logo"); +// Controls whether to use the covid-19 schedule or the regular schedule +const covid_schedule = true; +let current_schedule = covid_schedule ? "covid" : "regular"; + +// For testing. +// If this is set to a valid date/time string, that will be used instead of the +// current date and time. +let date_override = undefined; + let schedulesCallback = function(response) { schedules = response; redraw_clock(); @@ -104,15 +112,20 @@ function fitText(ctx, text, fontface, width) { } function update_lunch() { - switch(Number(document.getElementById("lunch_range").value)) { - case 0: - current_schedule = "regular-a"; - break; - case 1: - current_schedule = "regular-b"; - break; - case 2: - current_schedule = "regular-c"; + if (covid_schedule) { + current_schedule = "covid"; + } + else { + switch(Number(document.getElementById("lunch_range").value)) { + case 0: + current_schedule = "regular-a"; + break; + case 1: + current_schedule = "regular-b"; + break; + case 2: + current_schedule = "regular-c"; + } } redraw_clock(); } @@ -158,54 +171,50 @@ 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; } -function school_day() { - let now = new Date(); - if (now.getDay() % 6 === 0) { // If it's a weekend - return false; - } - return true; -} - function redraw_clock() { // Fake call to get_period_name to set current_schedule get_period_name("Period 1"); - // UTC to EST let number = 0; let period_name = ""; - // let now = Date.now() - 5 * 60 * 60 * 1000; - let now = Date.now() - 4 * 60 * 60 * 1000; - let tod = now % (24 * 60 * 60 * 1000); + const now = date_override ? new Date(date_override) : new Date(); + // Time of day + const tod = now.getHours() * 60 * 60 * 1000 + + now.getMinutes() * 60 * 1000 + + now.getSeconds() * 1000 + + now.getMilliseconds(); let pos; - if (school_day()) { - // let tod = 41399000; // Simulate time - + if (![0, 6].includes(now.getDay())) { + // School day let current_period_i = 0;// Get current period from array while (current_period_i < schedules[current_schedule].length - 1 && tod > schedules[current_schedule][current_period_i + 1].start) { current_period_i++; } - let current_period = schedules[current_schedule][current_period_i]; - let next_period = schedules[current_schedule][current_period_i + 1]; + const current_period = schedules[current_schedule][current_period_i]; + const next_period = schedules[current_schedule][current_period_i + 1]; - if(tod < current_period.start) { // Before school + if (tod < current_period.start) { // Before school period_name = "Before School"; pos = tod / current_period.start; number = current_period.start - tod; } - else if(!next_period && tod > current_period.end) { // After school + else if (!next_period && tod > current_period.end) { // After school // Realtime period_name = ""; pos = tod % (12 * 60 * 60 * 1000) / (12 * 60 * 60 * 1000); @@ -214,7 +223,7 @@ function redraw_clock() { number += 12 * 60 * 60 * 1000; } } - else if(tod > current_period.end) { // Between classes + else if (tod > current_period.end) { // Between classes period_name = get_period_name(current_period.name) + " ➡ " + get_period_name(next_period.name); pos = (tod - current_period.end) / (next_period.start - current_period.end); @@ -248,4 +257,3 @@ function redraw_clock() { drawHand(large_ctx, large_radius, pos, large_radius * .94, large_radius * .095); drawNumber(large_ctx, large_radius, pos, number); } - \ No newline at end of file diff --git a/public/schedule.json b/public/schedule.json index c792b0c3..5d5cc9fd 100755 --- a/public/schedule.json +++ b/public/schedule.json @@ -136,5 +136,32 @@ "start": 47400000, "end": 52200000 } + ], + "covid":[ + { + "name":"Period 1", + "start": 33000000, + "end": 36000000 + }, + { + "name":"Period 2", + "start": 36600000, + "end": 39600000 + }, + { + "name":"Period 3", + "start": 40200000, + "end": 43200000 + }, + { + "name":"Lunch", + "start": 43200000, + "end": 46800000 + }, + { + "name":"Period 4", + "start": 46800000, + "end": 49800000 + } ] }