Skip to content

fix(date-panel): fix date selection off-by-one day when clicking dates( #4138)#4263

Closed
Georgyhongbo wants to merge 1 commit into
opentiny:devfrom
Georgyhongbo:fix/date-panel-off-by-one
Closed

fix(date-panel): fix date selection off-by-one day when clicking dates( #4138)#4263
Georgyhongbo wants to merge 1 commit into
opentiny:devfrom
Georgyhongbo:fix/date-panel-off-by-one

Conversation

@Georgyhongbo

@Georgyhongbo Georgyhongbo commented Jul 26, 2026

Copy link
Copy Markdown

The modelValue watcher in date-panel incorrectly used getUTCDate() + 1 which caused a double timezone correction, resulting in the selected date being offset by one day. Changed to use getDate() which gives the correct local date value, consistent with how date-range and month-range components handle the same logic.

PR Checklist

Please check if your PR fulfills the following requirements:

  • The commit message follows our Commit Message Guidelines
  • Tests for the changes have been added (for bug fixes / features)
  • Docs have been added / updated (for bug fixes / features)

PR Type

What kind of change does this PR introduce?

  • Bugfix
  • Feature
  • Code style update (formatting, local variables)
  • Refactoring (no functional changes, no api changes)
  • Build related changes
  • CI related changes
  • Documentation content changes
  • Other... Please describe:

What is the current behavior?

When clicking a date in the DatePanel component, the wrong date is selected. For example, clicking "15" first selects "16". A second click on "15" is required to correctly select it. The bug occurs because the modelValue watcher applies a double timezone correction (val - localOffset plus getUTCDate() + 1), which shifts the date forward by one day.

Issue Number: N/A

What is the new behavior?

Clicking any date in DatePanel selects the correct date immediately, with no off-by-one error.

Does this PR introduce a breaking change?

  • Yes
  • No

Other information

Only one line changed in packages/renderless/src/date-panel/vue.ts. The fix aligns with how date-range and month-range already handle the same logic using getDate() instead of getUTCDate() + 1.

Summary by CodeRabbit

  • Bug Fixes
    • Improved date selection normalization across time zones.
    • Fixed displayed dates that could shift by one day for certain time zone offsets.

The modelValue watcher in date-panel incorrectly used getUTCDate() + 1
which caused a double timezone correction, resulting in the selected date
being offset by one day. Changed to use getDate() which gives the correct
local date value, consistent with how date-range and month-range components
handle the same logic.
@github-actions github-actions Bot added the bug Something isn't working label Jul 26, 2026
@coderabbitai

coderabbitai Bot commented Jul 26, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: cf7cd42d-3711-4c93-807f-7c1c958bdb37

📥 Commits

Reviewing files that changed from the base of the PR and between e5e921b and f9d9f80.

📒 Files selected for processing (1)
  • packages/renderless/src/date-panel/vue.ts

Walkthrough

The date-panel modelValue watcher now normalizes incoming dates using the local day component instead of a UTC-derived day.

Changes

Date normalization

Layer / File(s) Summary
Normalize incoming model values
packages/renderless/src/date-panel/vue.ts
The modelValue watcher passes newVal.getDate() to modifyDate when updating state.date and state.value.

Estimated code review effort: 1 (Trivial) | ~5 minutes

Possibly related PRs

Poem

A bunny hops through dates so bright,
No UTC twist can steal the night.
The local day now leads the way,
Keeping calendars right each day.
Carrots cheer the fix—hooray! 🐇

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main bug fix in date-panel and is specific enough for history scanning.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant