Skip to content

Instantly share code, notes, and snippets.

@itCarl
Last active March 19, 2023 16:19
Show Gist options
  • Save itCarl/2f6bebadb5e105672f5c88b60803f59e to your computer and use it in GitHub Desktop.
Save itCarl/2f6bebadb5e105672f5c88b60803f59e to your computer and use it in GitHub Desktop.
Ist die Woche ein grader oder ungrader Turnus
// Kalenderwoche, in denen schule ist.
const schoolWeeks = [ 2, 6, 9, 12, 17, 20, 23, 26 ];
const weekNumber = (d = new Date()) =>
{
let startDate = new Date(d.getFullYear(), 0, 1);
// EDIT: 19.03.2023
let days = Math.floor((d - startDate) / (7 * 24 * 60 * 60 * 1000));
return Math.ceil(days / 7);
};
const getCycle = () =>
{
const wn = schoolWeeks.indexOf(weekNumber());
return wn < 0
? 'Arbeitswoche'
: ( wn % 2
? 'odd week (u.T.)'
: 'regular week (g.T.)');
};
// Display the calculated result
console.log(getCycle());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment