"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.calculateDuration = exports.calculateBreakHours = void 0;
const date_fns_1 = require("date-fns");
const helpers_1 = require("./helpers");
const getMinutes = (start, end) => {
    if (!start || !end)
        return 0;
    const minutes = (0, date_fns_1.differenceInMinutes)(end, start);
    return Math.max(minutes, 0);
};
const calculateBreakHours = (lunchBreak, timeBreaks) => {
    let totalMinutes = 0;
    if (lunchBreak) {
        totalMinutes += getMinutes(lunchBreak.break_start, lunchBreak.break_end);
    }
    for (let i = 0; i < timeBreaks.length; i++) {
        const b = timeBreaks[i];
        totalMinutes += getMinutes(b.break_start, b.break_end);
    }
    const hours = totalMinutes / 60;
    return Math.max((0, helpers_1.roundHours)(hours), 0);
};
exports.calculateBreakHours = calculateBreakHours;
const calculateDuration = (start, end) => {
    const minutes = (0, date_fns_1.differenceInMinutes)(end, start);
    const hours = minutes / 60;
    return Math.max((0, helpers_1.roundHours)(hours), 0);
};
exports.calculateDuration = calculateDuration;
//# sourceMappingURL=attendance.js.map