From 5aa697468599c72d0ecd919de4a17b4e2cfee833 Mon Sep 17 00:00:00 2001 From: "sebastien.arod@gmail.com" Date: Tue, 4 Jun 2024 21:55:38 +0200 Subject: [PATCH] refactor: supprime les getTime() inutiles --- src/data/Famille.ts | 8 +++----- src/data/checkDataConsistency.ts | 2 +- src/period/generateConsecutivePeriods.ts | 6 +++--- src/period/isPeriodContaining.ts | 10 ++-------- 4 files changed, 9 insertions(+), 17 deletions(-) diff --git a/src/data/Famille.ts b/src/data/Famille.ts index 4cbb9c7..04bd7f5 100644 --- a/src/data/Famille.ts +++ b/src/data/Famille.ts @@ -52,15 +52,13 @@ export function periodOfResistance( if (family.Statut !== "Résistant.e" && family.Statut !== "Ex résistant·e·s") { return null; } - if (!family.Integration || family.Integration.getTime() > atDate.getTime()) { + if (!family.Integration || family.Integration > atDate) { return null; } return { start: family.Integration, end: - family.Sortie !== null && family.Sortie.getTime() < atDate.getTime() - ? family.Sortie - : atDate, + family.Sortie !== null && family.Sortie < atDate ? family.Sortie : atDate, }; } @@ -77,7 +75,7 @@ export function isExResistant( date: Date = new Date(Date.now()) ): boolean { const por = periodOfResistance(family, date); - return por !== null && por.end.getTime() < date.getTime(); + return por !== null && por.end < date; } export function isResistantOverPeriod( diff --git a/src/data/checkDataConsistency.ts b/src/data/checkDataConsistency.ts index 320212a..dfc5d33 100644 --- a/src/data/checkDataConsistency.ts +++ b/src/data/checkDataConsistency.ts @@ -39,7 +39,7 @@ function checkFamilyDataConsistency(family: Famille) { issueType: "Ex résistant.e.s without endResistant", }); } - if (family.Integration!.getTime() > family.Sortie!.getTime()) { + if (family.Integration! > family.Sortie!) { consistencyIssues.push({ familyId: family.Titre, issueType: "startResistsant > endResistant ", diff --git a/src/period/generateConsecutivePeriods.ts b/src/period/generateConsecutivePeriods.ts index 1bc9367..748063d 100644 --- a/src/period/generateConsecutivePeriods.ts +++ b/src/period/generateConsecutivePeriods.ts @@ -11,20 +11,20 @@ export default function generateConsecutivePeriods({ end?: Date; }): Period[] { const periods: Period[] = []; - if (start.getTime() < end.getTime()) { + if (start < end) { let nextPeriodStart = start; do { const periodStart = nextPeriodStart; nextPeriodStart = incrementStart(periodStart); const periodEnd = addMilliseconds(nextPeriodStart, -1); - if (periodEnd.getTime() < periodStart.getTime()) { + if (periodEnd < periodStart) { throw new Error("incrementStart call decremented date!!!"); } periods.push({ start: periodStart, end: periodEnd, }); - } while (nextPeriodStart.getTime() < end.getTime()); + } while (nextPeriodStart < end); } return periods; } diff --git a/src/period/isPeriodContaining.ts b/src/period/isPeriodContaining.ts index 90929b4..2947d54 100644 --- a/src/period/isPeriodContaining.ts +++ b/src/period/isPeriodContaining.ts @@ -5,14 +5,8 @@ export function isPeriodContaining( dateOrPeriod: Date | Period ): boolean { if (dateOrPeriod instanceof Date) { - return ( - period.start.getTime() <= dateOrPeriod.getTime() && - dateOrPeriod.getTime() <= period.end.getTime() - ); + return period.start <= dateOrPeriod && dateOrPeriod <= period.end; } else { - return ( - period.start.getTime() >= dateOrPeriod.start.getTime() && - dateOrPeriod.end.getTime() <= period.end.getTime() - ); + return period.start >= dateOrPeriod.start && dateOrPeriod.end <= period.end; } }