mirror of
https://framagit.org/enfance-libre/statistiques
synced 2025-12-07 23:03:47 +00:00
refactor: supprime les getTime() inutiles
This commit is contained in:
parent
88cc76bcce
commit
5aa6974685
4 changed files with 9 additions and 17 deletions
|
|
@ -52,15 +52,13 @@ export function periodOfResistance(
|
||||||
if (family.Statut !== "Résistant.e" && family.Statut !== "Ex résistant·e·s") {
|
if (family.Statut !== "Résistant.e" && family.Statut !== "Ex résistant·e·s") {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
if (!family.Integration || family.Integration.getTime() > atDate.getTime()) {
|
if (!family.Integration || family.Integration > atDate) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
return {
|
return {
|
||||||
start: family.Integration,
|
start: family.Integration,
|
||||||
end:
|
end:
|
||||||
family.Sortie !== null && family.Sortie.getTime() < atDate.getTime()
|
family.Sortie !== null && family.Sortie < atDate ? family.Sortie : atDate,
|
||||||
? family.Sortie
|
|
||||||
: atDate,
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -77,7 +75,7 @@ export function isExResistant(
|
||||||
date: Date = new Date(Date.now())
|
date: Date = new Date(Date.now())
|
||||||
): boolean {
|
): boolean {
|
||||||
const por = periodOfResistance(family, date);
|
const por = periodOfResistance(family, date);
|
||||||
return por !== null && por.end.getTime() < date.getTime();
|
return por !== null && por.end < date;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function isResistantOverPeriod(
|
export function isResistantOverPeriod(
|
||||||
|
|
|
||||||
|
|
@ -39,7 +39,7 @@ function checkFamilyDataConsistency(family: Famille) {
|
||||||
issueType: "Ex résistant.e.s without endResistant",
|
issueType: "Ex résistant.e.s without endResistant",
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
if (family.Integration!.getTime() > family.Sortie!.getTime()) {
|
if (family.Integration! > family.Sortie!) {
|
||||||
consistencyIssues.push({
|
consistencyIssues.push({
|
||||||
familyId: family.Titre,
|
familyId: family.Titre,
|
||||||
issueType: "startResistsant > endResistant ",
|
issueType: "startResistsant > endResistant ",
|
||||||
|
|
|
||||||
|
|
@ -11,20 +11,20 @@ export default function generateConsecutivePeriods({
|
||||||
end?: Date;
|
end?: Date;
|
||||||
}): Period[] {
|
}): Period[] {
|
||||||
const periods: Period[] = [];
|
const periods: Period[] = [];
|
||||||
if (start.getTime() < end.getTime()) {
|
if (start < end) {
|
||||||
let nextPeriodStart = start;
|
let nextPeriodStart = start;
|
||||||
do {
|
do {
|
||||||
const periodStart = nextPeriodStart;
|
const periodStart = nextPeriodStart;
|
||||||
nextPeriodStart = incrementStart(periodStart);
|
nextPeriodStart = incrementStart(periodStart);
|
||||||
const periodEnd = addMilliseconds(nextPeriodStart, -1);
|
const periodEnd = addMilliseconds(nextPeriodStart, -1);
|
||||||
if (periodEnd.getTime() < periodStart.getTime()) {
|
if (periodEnd < periodStart) {
|
||||||
throw new Error("incrementStart call decremented date!!!");
|
throw new Error("incrementStart call decremented date!!!");
|
||||||
}
|
}
|
||||||
periods.push({
|
periods.push({
|
||||||
start: periodStart,
|
start: periodStart,
|
||||||
end: periodEnd,
|
end: periodEnd,
|
||||||
});
|
});
|
||||||
} while (nextPeriodStart.getTime() < end.getTime());
|
} while (nextPeriodStart < end);
|
||||||
}
|
}
|
||||||
return periods;
|
return periods;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -5,14 +5,8 @@ export function isPeriodContaining(
|
||||||
dateOrPeriod: Date | Period
|
dateOrPeriod: Date | Period
|
||||||
): boolean {
|
): boolean {
|
||||||
if (dateOrPeriod instanceof Date) {
|
if (dateOrPeriod instanceof Date) {
|
||||||
return (
|
return period.start <= dateOrPeriod && dateOrPeriod <= period.end;
|
||||||
period.start.getTime() <= dateOrPeriod.getTime() &&
|
|
||||||
dateOrPeriod.getTime() <= period.end.getTime()
|
|
||||||
);
|
|
||||||
} else {
|
} else {
|
||||||
return (
|
return period.start >= dateOrPeriod.start && dateOrPeriod.end <= period.end;
|
||||||
period.start.getTime() >= dateOrPeriod.start.getTime() &&
|
|
||||||
dateOrPeriod.end.getTime() <= period.end.getTime()
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue