From 1305667f24e73d6996df115d64f0a54f297abae0 Mon Sep 17 00:00:00 2001 From: Pierre HUBERT Date: Thu, 20 Jun 2024 22:57:44 +0200 Subject: [PATCH] Fix date issues --- .../AccommodationsReservationsRoute.tsx | 5 +++-- geneit_app/src/utils/time_utils.ts | 15 +++++++++++---- geneit_app/src/widgets/forms/PropDateInput.tsx | 1 - 3 files changed, 14 insertions(+), 7 deletions(-) diff --git a/geneit_app/src/routes/family/accommodations/AccommodationsReservationsRoute.tsx b/geneit_app/src/routes/family/accommodations/AccommodationsReservationsRoute.tsx index 5f1099a..b47e03b 100644 --- a/geneit_app/src/routes/family/accommodations/AccommodationsReservationsRoute.tsx +++ b/geneit_app/src/routes/family/accommodations/AccommodationsReservationsRoute.tsx @@ -252,8 +252,9 @@ export function AccommodationsReservationsRoute(): React.ReactElement { const u = users?.find((u) => u.user_id === r.user_id); return { title: `${u?.user_name} - ${a.name}`, - start: fmtUnixDateFullCalendar(r.reservation_start), - end: fmtUnixDateFullCalendar(r.reservation_end), + start: fmtUnixDateFullCalendar(r.reservation_start, false), + end: fmtUnixDateFullCalendar(r.reservation_end, true), + allDay: true, color: a.color ? "#" + a.color : undefined, borderColor: r.validated === true diff --git a/geneit_app/src/utils/time_utils.ts b/geneit_app/src/utils/time_utils.ts index 56a3f1b..8b22197 100644 --- a/geneit_app/src/utils/time_utils.ts +++ b/geneit_app/src/utils/time_utils.ts @@ -8,18 +8,25 @@ export function fmtUnixDate(time: number): string { /** * Get formatted UNIX date for Full Calendar */ -export function fmtUnixDateFullCalendar(time: number): string { - const d = new Date(time * 1000); +export function fmtUnixDateFullCalendar( + time: number, + correctEnd: boolean +): string { + let d = new Date(time * 1000); + + if (d.getHours() > 0 && correctEnd) + d = new Date(time * 1000 + 3600 * 24 * 1000); const s = `${d.getFullYear()}-${(d.getMonth() + 1) .toString(10) - .padStart(2, "0")}-${d.getDate().toString(10).padStart(2, "0")}T${d + .padStart(2, "0")}-${d.getDate().toString(10).padStart(2, "0")}`; /*T${d .getHours() .toString(10) .padStart(2, "0")}:${d.getMinutes().toString(10).padStart(2, "0")}:${d .getSeconds() .toString(10) - .padStart(2, "0")}`; + .padStart(2, "0")}`*/ + console.log(s, d); return s; } diff --git a/geneit_app/src/widgets/forms/PropDateInput.tsx b/geneit_app/src/widgets/forms/PropDateInput.tsx index 46c457a..faafa8f 100644 --- a/geneit_app/src/widgets/forms/PropDateInput.tsx +++ b/geneit_app/src/widgets/forms/PropDateInput.tsx @@ -89,7 +89,6 @@ export function PropDateInput(p: { v = v.set("minutes", 0); v = v.set("seconds", 0); } - console.log(midDay, v, v.get("hours")); p.onChange(v.unix()); }}