Skip to content

Commit

Permalink
simplify and correct logic
Browse files Browse the repository at this point in the history
  • Loading branch information
C4illin committed May 3, 2024
1 parent 175c1d5 commit 2fa3aa1
Showing 1 changed file with 12 additions and 13 deletions.
25 changes: 12 additions & 13 deletions lasvecka-node/calc_date.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,16 +48,6 @@ function readDatePeriod(currDate) {
return { date: soughtDate, type: dateDict[soughtDate] };
}

function handleEaster(easterStartCheck, easterEndCheck) {
if (easterStartCheck >= 0 && easterEndCheck <= 0) {
return "Självstudier";
}
if (easterEndCheck > 0) {
const weeks = Math.floor(easterEndCheck / 7);
return `Lv ${weeks + 3}`;
}
}

function computeTime() {
// Find date where value is easter_start, easter_end and ord_cont in json file
const EASTER_START = dateDict.easter_start;
Expand All @@ -73,11 +63,20 @@ function computeTime() {
}
return "Tentavecka";
}
if (easterEndCheck >= 0 || easterStartCheck >= 0) {
return handleEaster(easterStartCheck, easterEndCheck);

let deltaT = currentDate.diff(moment(dat), "days");

if (easterStartCheck >= 0 && easterEndCheck <= 0) {
return "Självstudier";
}

if (easterEndCheck > 0) {
// the easter period is over and it is 7 days long
deltaT = deltaT - 7;
}
const deltaT = currentDate.diff(moment(dat), "days");

const weeks = Math.floor(deltaT / 7);

if (weeks > 7) {
return "Självstudier";
}
Expand Down

0 comments on commit 2fa3aa1

Please sign in to comment.