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" }); }