* helpers: parse date-only strings as local midnight - #247
Merged
Conversation
`createDate('2026-09-17')` handed the string straight to the Date constructor,
which treats a date-only ISO string as UTC midnight. In any time zone west of
UTC that is the previous local day, so `formatDate('2026-09-17', 'yyyy-MM-dd')`
returned `2026-09-16` and the date picker showed the day before the one the
user clicked (reproduced in ZenTao 22.5 with a browser in America/Edmonton).
Parse `YYYY-MM-DD` as local midnight, the same way `YYYY-MM-DD HH:mm:ss` is
already handled. Strings with a time part, timestamps and Date objects are
unchanged. Adds a unit test that runs in several time zones and a note in the
helper docs.
dalexhu
force-pushed
the
fix/create-date-local-midnight
branch
from
September 5, 2026 03:37
5059ee4 to
5861f06
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
问题
createDate('2026-09-17')把纯日期字符串直接交给Date构造函数,而按 ECMAScript 规范,YYYY-MM-DD这种只有日期的 ISO 串会被当作 UTC 零点。在 UTC 以西的时区里这就是本地的前一天:实际表现是日期选择器点 17 号,输入框里变成 16 号(在禅道 22.5 上复现,浏览器位于加拿大 Edmonton)。在 UTC+8 看不到这个问题,所以一直没被发现。
修改
createDate:匹配^\d{4}-\d{2}-\d{2}$的字符串改为按本地零点构造(new Date(year, month - 1, day)),与YYYY-MM-DD HH:mm:ss已有的本地时间语义一致。带时间的字符串、时间戳、Date对象的行为不变。America/Edmonton、Asia/Shanghai、UTC三个时区下验证纯日期串得到当天零点,并覆盖带Z的 ISO 串和带时间的字符串不受影响。未修复时该用例在 Edmonton 时区失败(得到[2026, 8, 16, 18]),修复后通过。date-helper.md增加一条提示说明纯日期串按本地时区解析。验证
pnpm exec vitest run tests/unit/helpers.test.ts:15 passedpnpm exec eslint对改动文件无告警;pnpm typecheck通过Summary (EN):
createDate()passed date-only ISO strings to theDateconstructor, which parses them as UTC midnight; in time zones west of UTC that is the previous local day, so date pickers showed the day before the one the user picked. ParseYYYY-MM-DDas local midnight instead; strings with a time part, timestamps andDateobjects are unchanged. Adds a multi-time-zone unit test and a docs note.🤖 Generated with Claude Code