From 372a2d16ab64326952c53781f778d765504e27d3 Mon Sep 17 00:00:00 2001 From: Jade Buckwalter Date: Sun, 14 Feb 2021 09:14:17 -0500 Subject: [PATCH 1/2] Fix bug with AM and PM classes Detect difference between AM and PM period names so they show up in the correct places --- public/js/clock.js | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/public/js/clock.js b/public/js/clock.js index c97c7fbb..00bf7904 100755 --- a/public/js/clock.js +++ b/public/js/clock.js @@ -234,8 +234,15 @@ function get_period_name(default_name, day_of_week) { } // period_names has class names now for (const { name, period } of period_names[bs_day]) { - if (period.slice(-1) === default_name.slice(-1)) - return name; + if (default_name.slice(-1) === "l") { + if (period.slice(0) === default_name.slice(0)) { + return name; + } + } else { + if (period.slice(-1) === default_name.slice(-1)) { + return name; + } + } } return default_name; } From 002124a740b1babe51a72473a8c51744eb3b43f8 Mon Sep 17 00:00:00 2001 From: psvenk <45520974+psvenk@users.noreply.github.com> Date: Tue, 16 Feb 2021 19:57:55 -0500 Subject: [PATCH 2/2] get_period_name: use a more robust algorithm Instead of relying solely on the last character of the period name, include explicit support for multiple period name formats so as to reduce the rate of false positives (e.g., "Before School" and "After School" being detected as the same period). --- public/js/clock.js | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/public/js/clock.js b/public/js/clock.js index 00bf7904..89f84e73 100755 --- a/public/js/clock.js +++ b/public/js/clock.js @@ -234,15 +234,15 @@ function get_period_name(default_name, day_of_week) { } // period_names has class names now for (const { name, period } of period_names[bs_day]) { - if (default_name.slice(-1) === "l") { - if (period.slice(0) === default_name.slice(0)) { - return name; - } - } else { - if (period.slice(-1) === default_name.slice(-1)) { - return name; - } - } + if (period === default_name) + return name; + // "BLOCK 1", "BLOCK 2", etc. + if (period === `BLOCK ${default_name.slice(-1)}`) + return name; + // For periods 1, 2, 3, 4 stored as strings containing "01", etc. + let match; + if ((match = period.match(/0\d/)) && default_name.includes(match[0])) + return name; } return default_name; }