From 1cc35f147df8e651f58c01442cac0fd1f8bb72c1 Mon Sep 17 00:00:00 2001 From: laoyang Date: Mon, 2 Nov 2026 14:48:28 +0800 Subject: [PATCH] =?UTF-8?q?fix(=E6=96=B0=E5=BB=BA=E6=97=A5=E7=A8=8B):=20?= =?UTF-8?q?=E9=9D=9E=E4=BB=8A=E5=A4=A9=E9=BB=98=E8=AE=A4=2009:00=EF=BC=8C?= =?UTF-8?q?=E4=BB=8A=E5=A4=A9=E4=BB=8D=E7=94=A8=E5=BD=93=E5=89=8D=E6=97=B6?= =?UTF-8?q?=E5=88=BB=20#4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 应用市场反馈:「新建非今天的日程时,默认时间固定在当天 9 点更好」。 根因:原来日期取所选日,但**时分固定取 now.getHours()**, 与所选日期无关。所以下午三点建明天的日程会得到「明天 15:00」。 改为按日期分支: · 今天 → 当前时刻(今天 09:00 往往已过,「现在就记一笔」才是常态) · 非今天 → 09:00(现在几点对别的日子没有参考价值) 顺带统一:toggleAllDay 关闭全天时原来硬编码 9 点,改为引用 DEFAULT_START_HOUR 常量,两处口径一致。 --- entry/src/main/ets/pages/EventEditPage.ets | 24 +++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/entry/src/main/ets/pages/EventEditPage.ets b/entry/src/main/ets/pages/EventEditPage.ets index c4d6eac..7f689d4 100644 --- a/entry/src/main/ets/pages/EventEditPage.ets +++ b/entry/src/main/ets/pages/EventEditPage.ets @@ -112,6 +112,8 @@ struct EventEditPage { @State sheetMode: string = 'picker'; @State pickerIsEnd: boolean = false; @State pickDate: Date = new Date(); + /** 新建"非今天"日程时的默认开始小时(24 小时制) */ + private static readonly DEFAULT_START_HOUR: number = 9; @State pickHour: number = 9; @State pickMin: number = 0; /** ⭐ 重复日程编辑范围:'one' 仅此次 / 'future' 此次及以后 / 'all' 全部 */ @@ -271,12 +273,23 @@ struct EventEditPage { return; } } - // 新建:日期取所选日(未选则今天),时间取当前时刻;结束 = 开始 + 1 小时 + // 新建:日期取所选日(未选则今天)。默认开始时刻分两种情况: + // ① 今天 → 取当前时刻("现在就记一笔"最自然;而且今天的 09:00 往往已经过了) + // ② 非今天 → 固定 09:00("现在几点"对别的日子毫无参考价值,09:00 才是通用默认) + // 结束时间统一 = 开始 + 1 小时。 const base: number = AppStorage.get('pendingEventDate') ?? Date.now(); - const dayStart = new Date(new Date(base).getFullYear(), new Date(base).getMonth(), - new Date(base).getDate()).getTime(); + const pickedDay = new Date(base); + const dayStart = new Date(pickedDay.getFullYear(), pickedDay.getMonth(), + pickedDay.getDate()).getTime(); const now = new Date(); - this.startMs = dayStart + now.getHours() * 3600000 + now.getMinutes() * 60000; + const todayStart = new Date(now.getFullYear(), now.getMonth(), now.getDate()).getTime(); + if (dayStart === todayStart) { + // ① 今天:当前时刻 + this.startMs = dayStart + now.getHours() * 3600000 + now.getMinutes() * 60000; + } else { + // ② 非今天:09:00 + this.startMs = dayStart + EventEditPage.DEFAULT_START_HOUR * 3600000; + } this.endMs = this.startMs + 3600000; if (choices.length > 0) { this.chosenKey = choices[0].calKey; @@ -686,7 +699,8 @@ struct EventEditPage { this.endMs = dayStart + 86399999; } else { const s = new Date(this.startMs); - this.startMs = s.getTime() + 9 * 3600000; + this.startMs = new Date(s.getFullYear(), s.getMonth(), s.getDate()).getTime() + + EventEditPage.DEFAULT_START_HOUR * 3600000; this.endMs = this.startMs + 3600000; } }