Skip to content

Commit

Permalink
feat(employees): check also for created date
Browse files Browse the repository at this point in the history
  • Loading branch information
italoteix committed May 20, 2021
1 parent 4ee55d9 commit 75942c0
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
18 changes: 15 additions & 3 deletions helpers/employee.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,20 @@
import isAfter from "date-fns/isAfter";
import { isAfter, endOfDay } from "date-fns";

// Check if employee was already created and yet active in a given date or time span
export function checkEmployeeAvailability(
employee: Employee,
compareDate: Date
startCompareDate: Date,
endCompareDate?: Date
) {
return !employee.endDate || isAfter(new Date(employee.endDate), compareDate);
const end = endCompareDate
? endOfDay(endCompareDate)
: endOfDay(startCompareDate);

if (end.getTime() < employee.created) {
return false;
}

return (
!employee.endDate || isAfter(new Date(employee.endDate), startCompareDate)
);
}
2 changes: 1 addition & 1 deletion store/reports/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ const actions: ActionTree<ReportsStoreState, RootStoreState> = {
);

const activeEmployees = employees.filter((employee) =>
checkEmployeeAvailability(employee, startDate)
checkEmployeeAvailability(employee, startDate, endDate)
);

commit("setIsLoading", { isLoading: false });
Expand Down

0 comments on commit 75942c0

Please sign in to comment.