fix: 할일 마감일 타임존 정규화
- 할일 생성/수정 시 마감일을 KST 기준 정오(12:00)로 정규화 - 클라이언트에서 전송된 날짜가 날짜 경계를 벗어나는 문제 해결
This commit is contained in:
@@ -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" });
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user