Skip to content

Commit

Permalink
Init commit
Browse files Browse the repository at this point in the history
  • Loading branch information
frc4533-lincoln authored Oct 3, 2024
1 parent f1fd705 commit b350774
Show file tree
Hide file tree
Showing 4 changed files with 135 additions and 0 deletions.
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@

## `dates.json` format

Each entry should include:
- `kind`: The kind of event (`break`, `holiday`, `elearning`, `teacher`, `early`, `half`)
- `start`: The start date

7 changes: 7 additions & 0 deletions dates.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[
{"kind": "early", "start": "2024-10-04"},
{"kind": "half", "start": "2024-10-18"},
{"kind": "holiday", "start": "2024-11-05"},
{"kind": "break", "start": "2024-11-25", "end": "2024-11-29"},
{"kind": "break", "start": "2024-12-23", "end": "2024-1-5"}
]
32 changes: 32 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<!DOCTYPE html>
<html>
<head>
<style>
body {
font-family: sans-serif;
text-align: center;
height: 100vh;
}
h3 {
font-weight: normal;
}
.main {
padding: 20vh 0 20vh 0;
}
</style>
</head>
<body>
<h1 style="margin-bottom:0pt">Are we free yet?</h1>
<p>Countdown to the next break, holiday, shortened schedule, or other not-having-to-go-to-school event</p>

<div class="main">
<h3><b>Next up:</b> <span id="kind"></span></h3>
<h1 id="countdown"></h1>
<p id="encouragement" hidden>Hold in there. Just a little longer.</p>
</div>

<p>This is a <a href="https://github.com/dragynfruit/arewefreeyet">free software</a> project from <a href="https://github.com/dragynfruit" target="_blank">Dragynfruit</a>.</p>

<script src="./index.js"></script>
</body>
</html>
89 changes: 89 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
(async function() {
const NORMAL_START = { "hour": 8, "min": 30 };
const NORMAL_END = { "hour": 15, "min": 35 };
const EARLY_END = { "hour": 13, "min": 30 };
const HALF_END = { "hour": 11, "min": 45 };

/**
* Load dates from our database
*/
async function loadDates() {
let res = await window.fetch('./dates.json');
let json = await res.text();
let dates = JSON.parse(json);

return dates;
}

function getNextDate(dates) {
var kind;

for (i in dates) {
let now = new Date(Date.now());
var date = new Date(dates[i]["start"]+' EST');

switch (dates[i]["kind"]) {
case 'break':
kind = 'Break';
break;
case 'holiday':
kind = 'Holiday';
break;
case 'elearning':
kind = 'E-learning';
break;
case 'teacher':
kind = 'Teacher workday';
break;
case 'early':
kind = 'Early Release';
date.setHours(EARLY_END.hour);
date.setMinutes(EARLY_END.min);
break;
case 'half':
kind = 'Half day';
date.setHours(HALF_END.hour);
date.setMinutes(HALF_END.min);
break;
}

if (now.getTime() < date.getTime()) {
return { "kind": kind, "start": date };
}
}
}

let dates = await loadDates();
let next = getNextDate(dates);
document.getElementById('kind').innerText = next["kind"];

setInterval(async function() {
// Get current time as milliseconds
let curr_time = new Date(Date.now()).getTime();
// Calculate diff between event start and current time
let countdown = next["start"].getTime() - curr_time;

var days = Math.floor(countdown / (1000 * 60 * 60 * 24));
var hours = Math.floor((countdown % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60));
var minutes = Math.floor((countdown % (1000 * 60 * 60)) / (1000 * 60));
var seconds = Math.floor((countdown % (1000 * 60)) / 1000);

// Timestamp for end of the current day
var currDayEnd = new Date(curr_time);
currDayEnd.setHours(NORMAL_END.hour);
currDayEnd.setMinutes(NORMAL_END.min);

// Timestamp for the start day of the event
var eventDayStart = new Date(next["start"]);
eventDayStart.setHours(NORMAL_START.hour);
eventDayStart.setMinutes(NORMAL_START.min);

document.getElementById('countdown').innerText = (days == 0)
? (curr_time > currDayEnd && curr_time < eventDayStart)
? 'Tomorrow'
: `${hours} hours, ${minutes} minutes, ${seconds} seconds`
: `${days} days, ${hours} hours, ${minutes} minutes, ${seconds} seconds`;

document.getElementById('encouragement').hidden = (curr_time > currDayEnd && curr_time < eventDayStart);
}, 100);
})();

0 comments on commit b350774

Please sign in to comment.