Skip to content

Commit

Permalink
Merge pull request #487 from CodingFactory-Repos/develop-G10
Browse files Browse the repository at this point in the history
[Hotfix] - Scan of hours
  • Loading branch information
AyakorK committed Jun 16, 2023
2 parents 5d3dbf9 + 5eba43d commit 10f749e
Showing 1 changed file with 21 additions and 9 deletions.
30 changes: 21 additions & 9 deletions back-end/src/base/calls/calls.repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -243,8 +243,8 @@ export class CallsRepository {
students: {
student: userObjectId,
presence: presence,
late: this.isStudentLate(period[periodIndex], date),
leftEarly: this.didStudentLeftEarly(period[periodIndex], date),
late: this.isStudentLate(period[periodIndex], this.getHour(date)),
leftEarly: this.didStudentLeftEarly(period[periodIndex], this.getHour(date)),
},
},
},
Expand All @@ -258,22 +258,34 @@ export class CallsRepository {
getDate(date) {
return new Date(Date.UTC(date.getFullYear(), date.getMonth(), date.getDate()));
}
getHour(date) {
return new Date(
Date.UTC(
date.getFullYear(),
date.getMonth(),
date.getDate(),
date.getHours(),
date.getMinutes(),
date.getSeconds(),
),
);
}
isStudentLate(period, timeOfScan) {
const fakeDate = new Date(
timeOfScan.getFullYear(),
timeOfScan.getMonth(),
timeOfScan.getDate(),
9,
11,
0,
0,
0,
);
if (period === 'arrival') {
if (timeOfScan >= 9 * 60 * 60 * 1000) {
const minutesOfLate = Math.floor(
Math.floor(timeOfScan.getTime() - fakeDate.getTime()) / 1000 / 60,
Math.floor(timeOfScan.getMinutes() - fakeDate.getMinutes()),
);
const hoursOfLate = Math.floor(minutesOfLate / 60);
const hoursOfLate = Math.floor(timeOfScan.getHours() - fakeDate.getHours());
const minutesOfLateConverted = minutesOfLate % 60;
return [true, `${hoursOfLate}h${minutesOfLateConverted}`];
}
Expand All @@ -287,18 +299,18 @@ export class CallsRepository {
timeOfScan.getFullYear(),
timeOfScan.getMonth(),
timeOfScan.getDate(),
17,
19,
0,
0,
0,
);
if (timeOfScan.getHours() == 14 && timeOfScan.getMinutes() < 50) {
const minutesOfLate = Math.floor(
Math.floor(fakeDate.getTime() - timeOfScan.getTime()) / 1000 / 60,
Math.floor(fakeDate.getMinutes() - timeOfScan.getMinutes()),
);
const hoursOfEarly = Math.floor(minutesOfLate / 60);
const hoursOfLate = Math.floor(fakeDate.getHours() - timeOfScan.getHours());
const minutesOfEarlyConverted = minutesOfLate % 60;
return [true, `${hoursOfEarly}h${minutesOfEarlyConverted}`];
return [true, `${hoursOfLate}h${minutesOfEarlyConverted}`];
}
}
return false;
Expand Down

0 comments on commit 10f749e

Please sign in to comment.