fix: 修复时间存储时区转换问题
直接存储前端发送的原始日期字符串,不做 toISOString 转换 避免本地时间被错误转换为 UTC 时间 Co-Authored-By: Claude (MiniMax-M2.1) <noreply@anthropic.com>
This commit is contained in:
parent
e3014a9d4c
commit
88fd057155
@ -6,12 +6,12 @@ import { asyncHandler } from '../middleware/errorHandler';
|
|||||||
|
|
||||||
const router = Router();
|
const router = Router();
|
||||||
|
|
||||||
// Validation schemas
|
// Validation schemas - date can be empty string for reminders
|
||||||
const createEventSchema = z.object({
|
const createEventSchema = z.object({
|
||||||
type: z.enum(['anniversary', 'reminder']),
|
type: z.enum(['anniversary', 'reminder']),
|
||||||
title: z.string().min(1, 'Title is required').max(200),
|
title: z.string().min(1, 'Title is required').max(200),
|
||||||
content: z.string().optional(),
|
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),
|
is_lunar: z.boolean().default(false),
|
||||||
repeat_type: z.enum(['yearly', 'monthly', 'none']).default('none'),
|
repeat_type: z.enum(['yearly', 'monthly', 'none']).default('none'),
|
||||||
is_holiday: z.boolean().default(false),
|
is_holiday: z.boolean().default(false),
|
||||||
@ -104,7 +104,9 @@ router.post(
|
|||||||
const data = createEventSchema.parse(req.body);
|
const data = createEventSchema.parse(req.body);
|
||||||
|
|
||||||
const eventId = crypto.randomUUID();
|
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({
|
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)
|
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 = ?');
|
updates.push('content = ?');
|
||||||
args.push(data.content);
|
args.push(data.content);
|
||||||
}
|
}
|
||||||
if (data.date) {
|
if (data.date !== undefined) {
|
||||||
updates.push('date = ?');
|
updates.push('date = ?');
|
||||||
args.push(new Date(data.date).toISOString());
|
// 直接存储原始字符串,不做时区转换
|
||||||
|
args.push(data.date || null);
|
||||||
}
|
}
|
||||||
if (data.is_lunar !== undefined) {
|
if (data.is_lunar !== undefined) {
|
||||||
updates.push('is_lunar = ?');
|
updates.push('is_lunar = ?');
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user