From c7cd31f622f054cde2f499e2b72b89f66d70c050 Mon Sep 17 00:00:00 2001 From: Sigrid Elnan <55406589+sigridge@users.noreply.github.com> Date: Wed, 24 Jul 2024 14:34:05 +0200 Subject: [PATCH] Fix bug that neither planned or used counted today (#507) --- backend/Core/DomainModels/Consultant.cs | 2 +- frontend/src/components/VacationCalendar.tsx | 8 ++++++-- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/backend/Core/DomainModels/Consultant.cs b/backend/Core/DomainModels/Consultant.cs index 2b04ea92..f3a4fc14 100644 --- a/backend/Core/DomainModels/Consultant.cs +++ b/backend/Core/DomainModels/Consultant.cs @@ -57,7 +57,7 @@ public int GetUsedVacationDays(DateOnly day) public int GetPlannedVacationDays(DateOnly day) { - return Vacations.Where(v => v.Date.Year.Equals(day.Year)).Count(v => v.Date > day); + return Vacations.Where(v => v.Date.Year.Equals(day.Year)).Count(v => v.Date >= day); } public int GetRemainingVacationDays(DateOnly day) diff --git a/frontend/src/components/VacationCalendar.tsx b/frontend/src/components/VacationCalendar.tsx index def5d859..65d061d2 100644 --- a/frontend/src/components/VacationCalendar.tsx +++ b/frontend/src/components/VacationCalendar.tsx @@ -136,6 +136,10 @@ export default function VacationCalendar({ onChange={handleChange} className="custom-calendar" mapDays={({ date }) => { + //Since the date object is created before the today object, an extra hour is added to a copied version of the date object to ensure that you can edit today + const dateCopy = new DateObject(date); + dateCopy.add(1, "h"); + let isWeekend = [0, 6].includes(date.weekDay.index); if ( vacationDays.vacationDays?.includes( @@ -147,7 +151,7 @@ export default function VacationCalendar({ date.day > 9 ? date.day.toString() : "0" + date.day.toString() }`, ) && - date.toDate() <= new Date() + dateCopy.toDate() < new Date() ) return { disabled: true, @@ -172,7 +176,7 @@ export default function VacationCalendar({ disabled: true, style: { color: "#B91456", opacity: 0.5 }, }; - else if (isWeekend || date.toDate() <= new Date()) + else if (isWeekend || dateCopy.toDate() < new Date()) return { disabled: true, style: { color: "#00445B", opacity: 0.5 },