fix: identify correct times in anomaly detection
This commit is contained in:
parent
51ba4a1f83
commit
8c585169d0
|
|
@ -2,13 +2,17 @@ import { Logger } from '@nestjs/common';
|
|||
import { Anomaly, Employee, Prisma, Tour } from '@prisma/client';
|
||||
import {
|
||||
Interval,
|
||||
addMilliseconds,
|
||||
addMinutes,
|
||||
format,
|
||||
getHours,
|
||||
getMinutes,
|
||||
isBefore,
|
||||
isWithinInterval,
|
||||
set,
|
||||
subMilliseconds,
|
||||
} from 'date-fns';
|
||||
import { fromZonedTime, toZonedTime } from 'date-fns-tz';
|
||||
import { getTimezoneOffset, toZonedTime } from 'date-fns-tz';
|
||||
|
||||
import { AnomalyTypes } from 'src/modules/feat-business-objects/entities/anomaly/anomaly-types.enum';
|
||||
import { AnomalyDetector } from './anomaly-detector.class';
|
||||
|
|
@ -100,7 +104,10 @@ export class EmployeesLoggedInDetector extends AnomalyDetector {
|
|||
},
|
||||
{
|
||||
description: `Zeitpunkt der Tour Anfahrt: ${format(
|
||||
toZonedTime(startOfTour, 'Europe/Berlin'),
|
||||
addMilliseconds(
|
||||
startOfTour,
|
||||
getTimezoneOffset('Europe/Berlin', startOfTour),
|
||||
),
|
||||
'HH:mm',
|
||||
)}`,
|
||||
},
|
||||
|
|
@ -108,14 +115,17 @@ export class EmployeesLoggedInDetector extends AnomalyDetector {
|
|||
? [
|
||||
{
|
||||
description: `Registrierte Anwesenheit: ${format(
|
||||
toZonedTime(attendanceInterval.start, 'Europe/Berlin'),
|
||||
addMilliseconds(
|
||||
attendanceInterval.start,
|
||||
getTimezoneOffset('Europe/Berlin', startOfTour),
|
||||
),
|
||||
'HH:mm',
|
||||
)}${
|
||||
attendanceInterval.end
|
||||
? ` - ${format(
|
||||
toZonedTime(
|
||||
addMilliseconds(
|
||||
attendanceInterval.end,
|
||||
'Europe/Berlin',
|
||||
getTimezoneOffset('Europe/Berlin', startOfTour),
|
||||
),
|
||||
'HH:mm',
|
||||
)}`
|
||||
|
|
@ -326,8 +336,22 @@ export class EmployeesLoggedInDetector extends AnomalyDetector {
|
|||
|
||||
private getStartOfTour(startDate: Date, startBegin: string) {
|
||||
if (!startBegin) return null;
|
||||
const zonedTime = toZonedTime(startDate, 'Europe/Berlin');
|
||||
|
||||
const [hours, minutes] = startBegin.split(':').map((v) => +v);
|
||||
return fromZonedTime(set(zonedTime, { hours, minutes }), 'Europe/Berlin');
|
||||
const tempDate = subMilliseconds(
|
||||
set(startDate, { hours, minutes }),
|
||||
getTimezoneOffset('Europe/Berlin', startDate),
|
||||
);
|
||||
const hourValue = getHours(tempDate);
|
||||
const minuteValue = getMinutes(tempDate);
|
||||
const modifiedTime = set(startDate, {
|
||||
hours: hourValue,
|
||||
minutes: minuteValue,
|
||||
});
|
||||
|
||||
// this.logger.debug(
|
||||
// `getStartOfTour(${startDate.toISOString()}, ${startBegin}): ${modifiedTime.toISOString()}`,
|
||||
// );
|
||||
return modifiedTime;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue