fix(notdienst): resolve timezone offset mismatch in plan generation and fix linter warning in calendar modal

This commit is contained in:
t.indorf
2026-05-21 12:53:46 +02:00
parent cf3fb82afe
commit 9915c8213e
4 changed files with 28 additions and 18 deletions
@@ -70,6 +70,7 @@ export function AdminTerminModal({
useEffect(() => { useEffect(() => {
if (open) { if (open) {
if (existingTermin) { if (existingTermin) {
// eslint-disable-next-line react-hooks/set-state-in-effect
setFormState({ setFormState({
title: existingTermin.title, title: existingTermin.title,
description: existingTermin.description || "", description: existingTermin.description || "",
+4 -3
View File
@@ -47,8 +47,8 @@ export async function generatePlanAction(year?: number, month?: number) {
where: { where: {
kitaId, kitaId,
date: { date: {
gte: new Date(targetYear, targetMonth - 1, 1), gte: new Date(Date.UTC(targetYear, targetMonth - 1, 1)),
lt: new Date(targetYear, targetMonth, 1), lt: new Date(Date.UTC(targetYear, targetMonth, 1)),
}, },
}, },
include: { child: { select: { familyId: true } } }, include: { child: { select: { familyId: true } } },
@@ -155,7 +155,8 @@ export async function updateAssignmentAction(
const session = await requireRole([UserRole.ADMIN, UserRole.KOORDINATOR]); const session = await requireRole([UserRole.ADMIN, UserRole.KOORDINATOR]);
const kitaId = session.user.kitaId!; const kitaId = session.user.kitaId!;
const parsedDate = new Date(date); const [yr, mo, dy] = date.slice(0, 10).split("-").map(Number);
const parsedDate = new Date(Date.UTC(yr, mo - 1, dy));
try { try {
await prisma.$transaction(async (tx) => { await prisma.$transaction(async (tx) => {
@@ -517,7 +517,8 @@ function PlanPreviewTable({
</div> </div>
<div className="divide-y divide-[var(--hairline-soft)]"> <div className="divide-y divide-[var(--hairline-soft)]">
{days.map((day) => { {days.map((day) => {
const dateObj = new Date(day.date); const [yr, mo, dy] = day.date.slice(0, 10).split("-").map(Number);
const dateObj = new Date(yr, mo - 1, dy);
const assignedChild = allChildren.find( const assignedChild = allChildren.find(
(child) => child.id === day.childId, (child) => child.id === day.childId,
); );
@@ -574,7 +575,8 @@ function ManualAssignmentTable({
</div> </div>
<div className="divide-y divide-[var(--hairline-soft)]"> <div className="divide-y divide-[var(--hairline-soft)]">
{days.map((day) => { {days.map((day) => {
const dateObj = new Date(day.date); const [yr, mo, dy] = day.date.slice(0, 10).split("-").map(Number);
const dateObj = new Date(yr, mo - 1, dy);
const assignedChild = allChildren.find( const assignedChild = allChildren.find(
(child) => child.id === day.childId, (child) => child.id === day.childId,
); );
+19 -13
View File
@@ -1,13 +1,8 @@
import { import {
addMonths, addMonths,
endOfMonth,
getDate, getDate,
getYear, getYear,
getMonth, getMonth,
isWeekend,
eachDayOfInterval,
startOfMonth,
startOfDay,
format, format,
} from "date-fns"; } from "date-fns";
import { de } from "date-fns/locale"; import { de } from "date-fns/locale";
@@ -36,17 +31,28 @@ export function getTargetMonthData(now = new Date()) {
} }
export function getWorkingDaysOfMonth(year: number, month: number) { export function getWorkingDaysOfMonth(year: number, month: number) {
// month ist 1-12, Date erwartet 0-11 const start = new Date(Date.UTC(year, month - 1, 1));
const start = startOfMonth(new Date(year, month - 1)); const end = new Date(Date.UTC(year, month, 0)); // last day of month
const end = endOfMonth(start);
const days = eachDayOfInterval({ start, end }); const days: Date[] = [];
const current = new Date(start);
return days while (current <= end) {
.filter((day) => !isWeekend(day)) const dayOfWeek = current.getUTCDay(); // 0 is Sunday, 6 is Saturday
.map((day) => startOfDay(day)); if (dayOfWeek !== 0 && dayOfWeek !== 6) {
days.push(new Date(current));
}
current.setUTCDate(current.getUTCDate() + 1);
}
return days;
} }
export function formatDateKey(date: Date) { export function formatDateKey(date: Date) {
return format(date, "yyyy-MM-dd"); return format(date, "yyyy-MM-dd");
} }
export function formatUtcDateKey(date: Date) {
const yyyy = date.getUTCFullYear();
const mm = String(date.getUTCMonth() + 1).padStart(2, "0");
const dd = String(date.getUTCDate()).padStart(2, "0");
return `${yyyy}-${mm}-${dd}`;
}