更新 readTasks 函數以將日期字串轉換為 Date 物件,確保任務的時間屬性正確處理。

This commit is contained in:
siage 2025-04-11 16:00:55 +08:00
parent 26ee08e8ca
commit 12c6d425d3

View File

@ -32,7 +32,15 @@ async function ensureDataDir() {
async function readTasks(): Promise<Task[]> { async function readTasks(): Promise<Task[]> {
await ensureDataDir(); await ensureDataDir();
const data = await fs.readFile(TASKS_FILE, "utf-8"); const data = await fs.readFile(TASKS_FILE, "utf-8");
return JSON.parse(data).tasks; const tasks = JSON.parse(data).tasks;
// 將日期字串轉換回 Date 物件
return tasks.map((task: any) => ({
...task,
createdAt: task.createdAt ? new Date(task.createdAt) : new Date(),
updatedAt: task.updatedAt ? new Date(task.updatedAt) : new Date(),
completedAt: task.completedAt ? new Date(task.completedAt) : undefined,
}));
} }
// 寫入所有任務 // 寫入所有任務