harvest-overtime
Version:
Track the overtime!
29 lines (28 loc) • 1.14 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.getOvertime = exports.getTimesheet = void 0;
const R = require("ramda");
const date_fns_1 = require("date-fns");
function getTimesheet(date, employees) {
const reportByDay = R.filter((n) => n.date === date, employees);
return {
date,
hours: R.sum(R.map((n) => n.hours, reportByDay)),
isWeekend: date_fns_1.isWeekend(date_fns_1.parseISO(date)),
};
}
exports.getTimesheet = getTimesheet;
function getOvertime(timesheet, regularDayHours) {
return {
weekdays: getOvertimeByType(timesheet, false, regularDayHours),
weekends: getOvertimeByType(timesheet, true, regularDayHours),
};
}
exports.getOvertime = getOvertime;
function getOvertimeByType(timesheet, isWeekEnd, regularDayHours) {
const hourListByDay = R.pipe(R.filter((n) => n.isWeekend === isWeekEnd), R.map((n) => n.hours))(timesheet);
const totalDays = hourListByDay.length;
const regularHours = isWeekEnd ? 0 : totalDays * regularDayHours;
const totalHours = R.sum(hourListByDay);
return totalHours - regularHours;
}