From cf51a64c788250b4eabfe69f5be4009cc584254f Mon Sep 17 00:00:00 2001 From: "kihong.kim" Date: Sun, 1 Feb 2026 01:45:53 +0900 Subject: [PATCH] =?UTF-8?q?fix:=20=ED=95=A0=EC=9D=BC=20=EB=A7=88=EA=B0=90?= =?UTF-8?q?=EC=9D=BC=20=ED=83=80=EC=9E=84=EC=A1=B4=20=EC=A0=95=EA=B7=9C?= =?UTF-8?q?=ED=99=94?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 할일 생성/수정 시 마감일을 KST 기준 정오(12:00)로 정규화 - 클라이언트에서 전송된 날짜가 날짜 경계를 벗어나는 문제 해결 --- backend/routes/todos.js | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/backend/routes/todos.js b/backend/routes/todos.js index 8818fa0..79a54a4 100644 --- a/backend/routes/todos.js +++ b/backend/routes/todos.js @@ -63,9 +63,22 @@ router.get("/today", async (req, res) => { } }); +// Normalize dueDate to noon KST to avoid timezone boundary issues +const normalizeDueDate = (dueDate) => { + if (!dueDate) return null; + // Parse the date and set it to noon KST + const date = DateTime.fromISO(dueDate, { zone: KST_TIMEZONE }); + // Set to noon (12:00) of that day in KST + return date.set({ hour: 12, minute: 0, second: 0, millisecond: 0 }).toJSDate(); +}; + router.post("/", async (req, res) => { try { - const todo = await Todo.create(req.body); + const todoData = { ...req.body }; + if (todoData.dueDate) { + todoData.dueDate = normalizeDueDate(todoData.dueDate); + } + const todo = await Todo.create(todoData); res.status(201).json(todo); } catch (error) { res.status(400).json({ message: "Failed to create todo" }); @@ -86,7 +99,11 @@ router.get("/:id", async (req, res) => { router.put("/:id", async (req, res) => { try { - const todo = await Todo.findByIdAndUpdate(req.params.id, req.body, { new: true }); + const updateData = { ...req.body }; + if (updateData.dueDate) { + updateData.dueDate = normalizeDueDate(updateData.dueDate); + } + const todo = await Todo.findByIdAndUpdate(req.params.id, updateData, { new: true }); if (!todo) { return res.status(404).json({ message: "Todo not found" }); }