Skip to content

fix(calendar) + feat(tasks): fix week start off-by-one & add due date with time support#271

Open
KrxkGit wants to merge 4 commits into
uphy:masterfrom
KrxkGit:master
Open

fix(calendar) + feat(tasks): fix week start off-by-one & add due date with time support#271
KrxkGit wants to merge 4 commits into
uphy:masterfrom
KrxkGit:master

Conversation

@KrxkGit

@KrxkGit KrxkGit commented Jul 3, 2026

Copy link
Copy Markdown

PR Description

Summary / 概述

This PR contains two independent changes:

本 PR 包含两个独立改动:


1. fix(calendar): Correct week start day off-by-one error / 修复日历周起始日错位问题

Problem / 问题:

When the user sets "Monday" as the first day of the week, the calendar header incorrectly starts from Tuesday. This is caused by using moment().weekday(n) (locale-relative offset) instead of moment().day(n) (absolute weekday index).

当用户将「周起始日」设置为 Monday 时,日历列头从 Tuesday 开始,存在一天的偏移。原因是代码中混用了 moment().weekday(n)(locale 相对偏移)和 moment().day(n)(绝对星期几索引)。

Fix / 修复:

Replace all moment().weekday(n) calls with moment().day(n) in Calendar.svelte and calendar.ts to ensure the week grid always aligns with the configured start day.

Calendar.sveltecalendar.ts 中的 weekday(n) 统一替换为 day(n),确保日历网格始终与配置的起始日对齐。

Files changed / 改动文件:

  • src/ui/Calendar.svelte
  • src/ui/calendar.ts

2. feat(tasks): Support due date with time for Tasks plugin format / 为 Tasks 插件格式新增精确时间支持

Background / 背景:

The Tasks plugin uses emoji-based fields (e.g. 📅 2024-01-01) for due dates but does not natively support a time component. This means when using the Tasks plugin format in obsidian-reminder, selecting a specific time via the date picker has no effect — the time is silently dropped and the reminder sidebar cannot show the exact reminder time.

Tasks 插件使用 emoji 字段(如 📅 2024-01-01)记录截止日期,但原生不支持具体时间。因此在 obsidian-reminder 中使用 Tasks 插件格式时,通过日期选择器选择的具体时间会被丢弃,reminder 侧边栏也无法显示精确提醒时间。

Solution / 方案:

Add a new toggle setting "Due Date With Time" (off by default) under the Tasks plugin format settings. When enabled, if the user selects a specific time, the reminder will write both the 📅 YYYY-MM-DD due date field and the ⏰ HH:mm time field to the markdown. The reminder sidebar will then correctly display the exact reminder time.

在 Tasks 插件格式设置中新增「Due Date With Time」开关(默认关闭)。开启后,若用户选择了具体时间,会同时向 markdown 写入 📅 YYYY-MM-DD 日期字段和 ⏰ HH:mm 时间字段,reminder 侧边栏可正确显示精确提醒时间。

Also fixed / 附带修复:

setReminderFormatConfig was not propagating config updates to static format instances, causing editor-extension.ts to always read stale config (e.g. dueDateWithTime always false).

setReminderFormatConfig 未将配置更新同步到各 format 静态实例,导致 editor-extension.ts 始终读取到旧配置(如 dueDateWithTime 始终为 false)。

Files changed / 改动文件:

  • src/model/format/reminder-tasks-plugin.ts
  • src/model/format/reminder-base.ts
  • src/model/format/index.ts
  • src/plugin/settings/index.ts
  • src/plugin/ui/editor-extension.ts
  • src/plugin/ui/date-chooser-modal.ts
  • src/ui/DateTimeChooser.svelte

Testing / 测试

  • Set week start to Monday → calendar header starts from Monday ✅
  • Enable "Due Date With Time" → selecting a time writes both 📅 and fields ✅
  • Disable "Due Date With Time" → behavior unchanged, only 📅 date written ✅
  • Reminder sidebar shows correct exact time when "Due Date With Time" is enabled ✅

KrxkGit added 4 commits July 3, 2026 14:19
Previously, only `modify`, `delete`, and `rename` vault events were
registered. When a sync tool (e.g. Remotely Save) writes a brand-new
file to the local vault, Obsidian fires a `create` event instead of
`modify`, so the reminders inside that file were never scanned and the
sidebar remained empty until the file was manually edited.

Add a `create` event listener with the same logic as `modify`:
reload reminders from the file and notify listeners if any were found.
使用 moment().day(n)(绝对星期几)替换 moment().weekday(n)(locale 相对偏移),
修复设置 Monday 为第一天时日历列头从 Tuesday 开始的错位问题。

Replace moment().weekday(n) with moment().day(n) (absolute weekday index)
to fix the off-by-one error where setting Monday as the first day of week
caused the calendar header to start from Tuesday instead of Monday.
weekday() is locale-relative while day() is always absolute (0=Sun, 1=Mon...).
Add a toggleable 'Due Date With Time' option (off by default) for the Tasks
plugin reminder format. When enabled and a specific time is selected, both
the due date emoji and time emoji fields are written to the markdown,
working around the Tasks plugin's lack of native time support so that the
reminder sidebar can display the exact reminder time.
Also fix setReminderFormatConfig not propagating config updates to static
format instances, which caused editor-extension.ts to read stale config.

为 Tasks 插件格式新增「Due Date With Time」开关(默认关闭)。
开启后,选择具体时间时会同时写入日期和时间两个字段,
弥补 Tasks 插件原生不支持精确时间的限制,reminder 侧边栏可正确显示精确提醒时间。
同时修复了 setReminderFormatConfig 未同步更新各 format 静态实例 config 的问题。
fix: trigger (@) does not open date chooser on iOS

移除 buildCodeMirrorPlugin 注册时的 Platform.isDesktopApp 判断,
使 CodeMirror 6 扩展在移动端也能正常注册并响应输入触发。
date-chooser-modal.ts 已有移动端适配,弹窗在 iOS 上可正常工作。

Remove the Platform.isDesktopApp guard around buildCodeMirrorPlugin
registration so the CodeMirror 6 extension is also registered on mobile.
The date-chooser-modal already handles mobile layout via Platform.isDesktop,
so the modal works correctly on iOS.
@uphy

uphy commented Jul 11, 2026

Copy link
Copy Markdown
Owner

Thank you for the contribution. The calendar off-by-one analysis is correct and valuable — weekStart being applied both as an absolute weekday index and via moment.updateLocale(..., {week: {dow}}) does double-offset weekday() calls, and switching to day() is the right fix. However, the PR as a whole needs rework before any of it can merge:

  1. Please split this into separate PRs. The description says "two independent changes", but the branch actually contains four unrelated ones: (a) the calendar off-by-one fix, (b) the Tasks-format due-date-with-time feature, (c) subscribing to the vault create event, and (d) removing the Platform.isDesktopApp guard for mobile. Each needs to be reviewable and revertable on its own. In particular (d) is a broad behavioral change that isn't mentioned anywhere in the PR description — if you believe it's needed, please open it separately with an explanation and evidence of mobile testing.
  2. Rewrite everything in English. Per the repository convention, all artifacts — code comments, commit messages, PR title/description — must be written in English. The added comments in src/model/format/index.ts, src/model/format/reminder-tasks-plugin.ts, and src/ui/DateTimeChooser.svelte are currently in Chinese; please translate them all.
  3. Fix lint. ReminderFormatParameterKey is imported but unused in src/model/format/index.ts, which fails unused-imports/no-unused-imports. Please run npm run lint:fix locally.
  4. Complete the calendar fix. weekStart is only propagated through editor-extension.ts; the autocomplete.ts / datetime-chooser.ts paths still open the chooser without it, so those entry points remain Sunday-based.
  5. Reconsider dueDateWithTime × useCustomEmoji. The new setTime() unconditionally overwrites the 📅 due date, bypassing the existing "Distinguish between reminder date and due date" behavior — with both toggles on, an independently-set due date gets silently overwritten, contradicting the setting description. Either make the two settings genuinely independent or make the conflict explicit.
  6. Add tests. Both src/ui/calendar.ts and src/model/format/reminder-tasks-plugin.ts have existing test files; please cover weekStart != 0 and the dueDateWithTime on/off (and combination with useCustomEmoji) cases.
  7. Rebase onto the latest master — the branch currently conflicts with the recent settings/DI refactors.

Happy to review the split PRs once they're ready.

@uphy uphy added awaiting-response Waiting for a response from the PR author; auto-closed after prolonged inactivity pinned Exempt from the stale auto-close workflow and removed pinned Exempt from the stale auto-close workflow labels Jul 11, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

awaiting-response Waiting for a response from the PR author; auto-closed after prolonged inactivity

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants