CRLSCSClub / CRLSTime

A clock for showing the CRLS schedule during the school day
6 stars 10 forks source link

black/silver days (issue #3) #37

Open Derp7777 opened 5 years ago

Derp7777 commented 5 years ago

right now, the barebones black/silver feature has a table with every single black/silver date (only 5 so far, but the plan appears to be to have them all). this is obviously inefficient and needs to be fixed. We will make a function that automatically changes the day at the start of each day, then we will make an array of dates where it should not change (say, for breaks/days off and modified schedules). they release the b/s calendar at the start of the year so we will be able to hard-code this every year. at the start of the day, something will run like IF getDate() NOT IN dontSwitch: switchBS()

jr2035121 commented 5 years ago

Here's the black/silver day schedule: https://crls.cpsd.us/UserFiles/Servers/Server_3045299/File/students/crls_calendar-2018-19.pdf, and you can get it from: https://crls.cpsd.us/calendar, year in view-calendar

Derp7777 commented 5 years ago
var date = new Date();
function shouldChangeBS(dontChange) {
// dontChange is array of nested arrays with two ints each (eg [3,13] for 3/13)
// dontChange would look like [[3,12],[3,13],etc]
// currentDate would be like one of the dates (like [3,13])
return (dontChange.indexOf([date.getMonth() + 1, date.getDate()]) == -1);
}

// this part runs at the start of every day, just before the clock is changed to the main schedule
if (shouldChangeBS(dontChange) && date.getDay() != 6 && date.getDay() != 0) { 
// this is separate from the function so blackOrSilver does not need to be global or an input of shouldChangeBS
    if (blackOrSilver = "Silver") {
        blackOrSilver = "Black";
    } else {
        blackOrSilver = "Silver";
}
Derp7777 commented 5 years ago

since the main code is skipped whenever it's a holiday, the dontChange array would only need like 7 or 8 days in it, which is far less than every single black day or every single silver day, which would each be around 90.