klnodekb/test.js

112 lines
3.6 KiB
JavaScript

const moment=require("moment")
const start="2025.02.07. 6:59"
const stop="2025.02.07. 17:12"
const lunchtime=1*60
const expectedWorkHours=8*60
const overHourThreshold=1*60
function convertMinsToHrsMins(minutes) {
var h = Math.floor(minutes / 60);
var m = minutes % 60;
h = h < 10 ? '0' + h : h;
m = m < 10 ? '0' + m : m;
return h + ':' + m;
}
/*function convertMinsToHrsMins(minutes) {
const hours = Math.floor(minutes / 60);
const remainingMinutes = minutes % 60;
console.log("remainingminutes: "+remainingMinutes)
return `${String(hours).padStart(2, '0')}:${String(remainingMinutes).padStart(2, '0')}`;
}*/
var fullTime=moment(stop,"YYYY.MM.DD. HH.mm").diff(moment(start,"YYYY.MM.DD. HH.mm"),"minutes")
const fl=fullTime-lunchtime; // Teljes idő - ebéd idő
const oh=fl-expectedWorkHours;
const wh=fl-(fl-expectedWorkHours);
var overHours=0;
if (oh>overHourThreshold) overHours=oh; else overHours=0;
var workHours=fl>=expectedWorkHours?wh:fl
console.log(`Full Time: ${convertMinsToHrsMins(fullTime)}
Lunch: ${convertMinsToHrsMins(lunchtime)}
WorkHour: ${convertMinsToHrsMins(workHours)}
OverHour: ${convertMinsToHrsMins(overHours)}`)
/*
if (element.startStop[element.startStop.length-1].stop!='-')
{
if (element.isWeekend)
{
if (element.fullHours>540)
{ // A túlórát nem számoljuk a munkaidő közé
element.hours=540;
if (element.fullHours>=600)
{
element.overTime=element.fullHours-element.hours;
}
else
{
element.overTime=0;
}
}
else
{
element.hours=element.fullHours;
element.overTime=0;
}
if (day===6) // Szombat
{
weekend.Saturday.workHours+=element.hours;
weekend.Saturday.overTime+=element.overTime;
//weekend.Saturday.fullWorkHours+=element.fullHours;
weekend.Saturday.fullWorkHours+=(element.hours+element.overTime);
weekend.Saturday.days+=1;
}
if (day===0) // Vasárnap
{
weekend.Sunday.workHours+=element.hours;
weekend.Sunday.overTime+=element.overTime;
//weekend.Sunday.fullWorkHours+=element.fullHours;
weekend.Sunday.fullWorkHours+=(element.hours+element.overTime);
weekend.Sunday.days+=1;
}
}
else
{
if (element.fullHours>540)
{ // A túlórát nem számoljuk a munkaidő közé
element.hours=540;
//element.overTime=element.fullHours-element.hours;
if (element.fullHours>=600)
{
element.overTime=element.fullHours-element.hours;
}
else
{
element.overTime=0;
}
}
else
{
element.hours=element.fullHours;
element.overTime=0;
}
month.workHours+=element.hours;
month.overTime+=element.overTime;
//month.fullWorkHours+=element.fullHours;
month.fullWorkHours+=(element.hours+element.overTime);
//monthWorkHours+= element.hours;
//monthOverTime+=element.overTime;
// Ha hétköznap
}
}
*/