From 88fd0571558235cda44370cb5d4016287511e2bd Mon Sep 17 00:00:00 2001 From: ddshi <8811906+ddshi@user.noreply.gitee.com> Date: Tue, 3 Feb 2026 14:57:52 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=E6=97=B6=E9=97=B4?= =?UTF-8?q?=E5=AD=98=E5=82=A8=E6=97=B6=E5=8C=BA=E8=BD=AC=E6=8D=A2=E9=97=AE?= =?UTF-8?q?=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 直接存储前端发送的原始日期字符串,不做 toISOString 转换 避免本地时间被错误转换为 UTC 时间 Co-Authored-By: Claude (MiniMax-M2.1) --- src/routes/events.ts | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/src/routes/events.ts b/src/routes/events.ts index 825c6b4..f72c05b 100644 --- a/src/routes/events.ts +++ b/src/routes/events.ts @@ -6,12 +6,12 @@ import { asyncHandler } from '../middleware/errorHandler'; const router = Router(); -// Validation schemas +// Validation schemas - date can be empty string for reminders const createEventSchema = z.object({ type: z.enum(['anniversary', 'reminder']), title: z.string().min(1, 'Title is required').max(200), content: z.string().optional(), - date: z.string().datetime(), // ISO datetime string + date: z.string().optional(), // Can be empty for reminders is_lunar: z.boolean().default(false), repeat_type: z.enum(['yearly', 'monthly', 'none']).default('none'), is_holiday: z.boolean().default(false), @@ -104,7 +104,9 @@ router.post( const data = createEventSchema.parse(req.body); const eventId = crypto.randomUUID(); - const dateValue = new Date(data.date).toISOString(); + // Handle empty date - store as null for reminders without specific time + // 直接存储前端发送的原始日期字符串,不做 toISOString 转换(避免时区问题) + const dateValue = data.date || null; await db.execute({ sql: `INSERT INTO events (id, user_id, type, title, content, date, is_lunar, repeat_type, is_holiday, is_completed, created_at, updated_at) @@ -154,9 +156,10 @@ router.put( updates.push('content = ?'); args.push(data.content); } - if (data.date) { + if (data.date !== undefined) { updates.push('date = ?'); - args.push(new Date(data.date).toISOString()); + // 直接存储原始字符串,不做时区转换 + args.push(data.date || null); } if (data.is_lunar !== undefined) { updates.push('is_lunar = ?');