80 lines
3.1 KiB
TypeScript
80 lines
3.1 KiB
TypeScript
// import { BadRequestException, Injectable, Logger } from "@nestjs/common";
|
|
// import { PrismaService } from "../prisma/prisma.service";
|
|
|
|
|
|
// //THIS SERVICE IS NOT USED, RULES TO BE DETERMINED WITH MIKE/HR/ACCOUNTING
|
|
// @Injectable()
|
|
// export class AfterHoursService {
|
|
// private readonly logger = new Logger(AfterHoursService.name);
|
|
// private static readonly BUSINESS_START = 7;
|
|
// private static readonly BUSINESS_END = 18;
|
|
// private static readonly ROUND_MINUTES = 15;
|
|
|
|
// constructor(private readonly prisma: PrismaService) {}
|
|
|
|
|
|
// private getPreBusinessMinutes(start: Date, end: Date): number {
|
|
// const biz_start = new Date(start);
|
|
// biz_start.setHours(AfterHoursService.BUSINESS_START, 0,0,0);
|
|
|
|
// if (end>= start || start >= biz_start) {
|
|
// return 0;
|
|
// }
|
|
|
|
// const segment_end = end < biz_start ? end : biz_start;
|
|
// const minutes = (segment_end.getTime() - start.getTime()) / 60000;
|
|
|
|
// this.logger.debug(`getPreBusinessMintutes -> ${minutes.toFixed(1)}min`);
|
|
// return minutes;
|
|
|
|
// }
|
|
|
|
// private getPostBusinessMinutes(start: Date, end: Date): number {
|
|
// const biz_end = new Date(start);
|
|
// biz_end.setHours(AfterHoursService.BUSINESS_END,0,0,0);
|
|
|
|
// if( end <= biz_end ) {
|
|
// return 0;
|
|
// }
|
|
|
|
// const segment_start = start > biz_end ? start : biz_end;
|
|
// const minutes = (end.getTime() - segment_start.getTime()) / 60000;
|
|
|
|
// this.logger.debug(`getPostBusinessMintutes -> ${minutes.toFixed(1)}min`);
|
|
// return minutes;
|
|
|
|
// }
|
|
|
|
// private roundToNearestQUarterMinute(minutes: number): number {
|
|
// const rounded = Math.round(minutes / AfterHoursService.ROUND_MINUTES)
|
|
// * AfterHoursService.ROUND_MINUTES;
|
|
// this.logger.debug(`roundToNearestQuarterMinute -> raw=${minutes.toFixed(1)}min, rounded= ${rounded}min`);
|
|
// return rounded;
|
|
// }
|
|
|
|
// public computeAfterHours(start: Date, end:Date): number {
|
|
// if(end.getTime() <= start.getTime()) {
|
|
// throw new BadRequestException('The end cannot be before the starting of the shift');
|
|
// }
|
|
|
|
// if (start.toDateString() !== end.toDateString()) {
|
|
// throw new BadRequestException('you cannot enter a shift that start in a day and end in the next' +
|
|
// 'You must create 2 instances, one on the first day and the second during the next day.');
|
|
// }
|
|
|
|
// const pre_min = this.getPreBusinessMinutes(start, end);
|
|
// const post_min = this.getPostBusinessMinutes(start, end);
|
|
// const raw_aftermin = pre_min + post_min;
|
|
|
|
// const rounded_min = this.roundToNearestQUarterMinute(raw_aftermin);
|
|
|
|
// const hours = rounded_min / 60;
|
|
// const result = parseFloat(hours.toFixed(2));
|
|
|
|
// this.logger.debug(`computeAfterHours -> raw_aftermin = ${raw_aftermin.toFixed(1)}min, +
|
|
// rounded = ${rounded_min}min, hours = ${result.toFixed(2)}`);
|
|
// return result;
|
|
// }
|
|
// }
|
|
|