Skip to content

Commit

Permalink
fix: merge
Browse files Browse the repository at this point in the history
  • Loading branch information
maxgfr committed Jan 29, 2024
1 parent 477e78f commit 239193d
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ describe("Accumulation d'absence par année", () => {
${[{ durationInMonth: 1, motif: { value: 1 }, startedAt: "02/06/2020" }]} | ${[{ begin: date2020, end: exitIn2020 }]} | ${[{ totalAbsenceInMonth: 1, year: 2020 }]}
${[{ durationInMonth: 1, motif: { value: 1 }, startedAt: "10/05/2020" }, { durationInMonth: 2, motif: { value: 1 }, startedAt: "10/07/2020" }]} | ${[{ begin: date2020, end: exitIn2020 }]} | ${[{ totalAbsenceInMonth: 3, year: 2020 }]}
${[{ durationInMonth: 3, motif: { value: 1 }, startedAt: "10/07/2020" }, { durationInMonth: 2, motif: { value: 1 }, startedAt: "10/04/2021" }]} | ${[{ begin: date2020, end: date2021LessOneDay }, { begin: date2021, end: exitIn2021 }]} | ${[{ totalAbsenceInMonth: 3, year: 2020 }, { totalAbsenceInMonth: 2, year: 2021 }]}
${[{ durationInMonth: 1, motif: { value: 1 }, startedAt: "20/03/2021" }]} | ${[{ begin: date2020, end: date2021LessOneDay }, { begin: date2021, end: exitIn2021 }]} | ${[{ totalAbsenceInMonth: 0.4666666666666667, year: 2020 }, { totalAbsenceInMonth: 0.4666666666666667, year: 2021 }]}
${[{ durationInMonth: 1, motif: { value: 1 }, startedAt: "20/03/2021" }]} | ${[{ begin: date2020, end: date2021LessOneDay }, { begin: date2021, end: exitIn2021 }]} | ${[{ totalAbsenceInMonth: 0.5, year: 2020 }, { totalAbsenceInMonth: 0.5, year: 2021 }]}
`(
"Avec $absences.length absence(s) et $years.length année(s) on attend $expectedOutput.length découpe(s) par année",
({ absences, years, expectedOutput }) => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import type { Interval } from "date-fns";
import {
add,
addDays,
addMonths,
areIntervalsOverlapping,
differenceInCalendarMonths,
Expand Down Expand Up @@ -170,7 +171,11 @@ const getOverlappingMonthsInterval = (r1: Interval, r2: Interval) => {
const end = min([r1.end, r2.end]);
const diffInMonths = differenceInCalendarMonths(end, start);
const startDateWithDifferenceInMonths = addMonths(start, diffInMonths);
const diffInDays = differenceInDays(end, startDateWithDifferenceInMonths);
const endWithOneDay = addDays(end, 1);
const diffInDays = differenceInDays(
endWithOneDay,
startDateWithDifferenceInMonths
);
return diffInMonths + diffInDays / 30;
} else return 0;
};

0 comments on commit 239193d

Please sign in to comment.