diff --git a/packages/code-du-travail-modeles/src/modeles/common/utils/__tests__/accumulate-absence-by-year.spec.ts b/packages/code-du-travail-modeles/src/modeles/common/utils/__tests__/accumulate-absence-by-year.spec.ts index b6c48f8a77..91070e221e 100644 --- a/packages/code-du-travail-modeles/src/modeles/common/utils/__tests__/accumulate-absence-by-year.spec.ts +++ b/packages/code-du-travail-modeles/src/modeles/common/utils/__tests__/accumulate-absence-by-year.spec.ts @@ -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 }) => { diff --git a/packages/code-du-travail-modeles/src/modeles/common/utils/seniority.ts b/packages/code-du-travail-modeles/src/modeles/common/utils/seniority.ts index 99a9fafa23..3262530278 100644 --- a/packages/code-du-travail-modeles/src/modeles/common/utils/seniority.ts +++ b/packages/code-du-travail-modeles/src/modeles/common/utils/seniority.ts @@ -1,6 +1,7 @@ import type { Interval } from "date-fns"; import { add, + addDays, addMonths, areIntervalsOverlapping, differenceInCalendarMonths, @@ -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; };