Skip to content

Conversation

@composable-tu
Copy link
Contributor

@composable-tu composable-tu commented Aug 19, 2025

🤔 这个 PR 的性质是?

  • 日常 bug 修复

🔗 相关 Issue

fix #3860

当组件开启 show-weekstart="{{nowTime()}}" 时,「日」列表界面与未开启 show-week 的「日」列表界面不一致:

  1. 开启 show-week 时「日」列显示了 nowTime() 之前的日期,关闭 show-week 后则消失。
  2. 开启 show-week 时,steps 步长设置对「日」不生效,关闭则正常。

💡 需求背景和解决方案

应该是在 getOptionByType(type: string) 函数中,if (type === 'date' && showWeek) 直接返回了 getDaysOfWeekInMonth(this.date) 的结果,忽视了 startendsteps 值。

getDaysOfWeekInMonth(date: Dayjs): Array<{ value: string; label: string }> {
const { locale, dayjsLocale } = this.data;
const startOfMonth = date.startOf('month');
const endOfMonth = date.endOf('month');
const daysOfWeek = [];
for (let i = 0; i <= endOfMonth.diff(startOfMonth, 'days'); i += 1) {
const currentDate = startOfMonth.add(i, 'days').locale(dayjsLocale);
const dayName = currentDate.format('ddd');
daysOfWeek.push({
value: `${i + 1}`,
label: `${i + 1}${locale.date || ''} ${dayName}`,
});
}
return daysOfWeek;
},

我这里把上述函数代码改成以下代码就可以了:

    getDaysOfWeekInMonth(date: Dayjs, type: string): Array<{ value: string; label: string }> {
      const { locale, steps, dayjsLocale } = this.data;
      const startOfMonth = date.startOf('month');
      const minEdge = this.getOptionEdge('min', type);
      const maxEdge = this.getOptionEdge('max', type);
      const step = steps?.[type] ?? 1;
      const daysOfWeek = [];

      for (let i = minEdge; i <= maxEdge; i += step) {
        const currentDate = startOfMonth.date(i).locale(dayjsLocale);
        const dayName = currentDate.format('ddd');
        daysOfWeek.push({
          value: `${i}`,
          label: `${i}${locale.date || ''} ${dayName}`,
        });
      }

      return daysOfWeek;
    },

📝 更新日志

  • fix(DateTimePicker): 修复 showWeek 模式下日(date)列表未正确排除 startend、且 steps 步长无效的问题

☑️ 请求合并前的自查清单

⚠️ 请自检并全部勾选全部选项⚠️

  • 文档无须补充
  • 代码演示无须提供
  • TypeScript 定义无须补充
  • Changelog 已提供

@pkg-pr-new
Copy link

pkg-pr-new bot commented Aug 19, 2025

Open in StackBlitz

npm i https://pkg.pr.new/tdesign-miniprogram@3861

commit: 8ae177e

@anlyyao anlyyao requested a review from Copilot August 22, 2025 09:06
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR fixes a bug in the DateTimePicker component where the day list in showWeek mode was not properly excluding dates outside the start and end range. When show-week was enabled with start="{{nowTime()}}", the day list showed dates before the start time that should have been filtered out.

  • Added proper date range validation using getMinDate() and getMaxDate() methods
  • Modified the day generation logic to skip dates outside the allowed range
  • Implemented early loop termination when reaching the maximum date

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

重构 getDaysOfWeekInMonth 方法,使用 getOptionEdge 获取边界值并支持步长配置,简化循环逻辑,移除不必要的日期范围检查
@composable-tu composable-tu requested a review from anlyyao August 22, 2025 11:08
@composable-tu composable-tu changed the title fix(DateTimePicker): 修复在 showWeek 模式下日列表未正确排除 start 和 end 的 Bug fix(DateTimePicker): 修复在 showWeek 模式下日列表未正确排除 start、end、且 steps 步长不生效的 Bug Aug 22, 2025
@anlyyao anlyyao merged commit cdc4163 into Tencent:develop Aug 25, 2025
7 checks passed
anlyyao added a commit that referenced this pull request Aug 29, 2025
* fix(DateTimePicker): 修复在 showWeek 模式下日列表未正确排除 start、end、且 steps 步长不生效的 Bug (#3861)

* fix(DateTimePicker): 修复在 showWeek 模式下日列表未正确排除 start 和 end 的 Bug

* refactor(date-time-picker): 优化日期周显示逻辑,使用统一边界和步长控制

重构 getDaysOfWeekInMonth 方法,使用 getOptionEdge 获取边界值并支持步长配置,简化循环逻辑,移除不必要的日期范围检查

* refactor: use monorepo (#3660)

* chore: directory structure optimization

* chore: update coverage badges

* chore: update dependency installation to use pnpm action

* chore: the respective package.json

* chore: move test to root dir

* chore: update jest config

* chore: update typos-config

* chore: update typos-config

* chore: update import path

* chore: lint

* chore: update script

* chore: update plugin script

* chore: update script

* chore: update deps

* chore: update dep

* chore: support ty live host

* chore: update live host

* chore: update badge script data path

* chore: update vscode setting and nest files

---------

Co-authored-by: novlan1 <[email protected]>

* chore: update group code path (#3880)

* fix(Message): use the correct error theme icon (#3879)

* fix(Message): use the correct error theme icon

* test: update snapshots

---------

Co-authored-by: novlan1 <[email protected]>

* docs: add pkg.pr.new badge (#3882)

* chore(Textarea): using pseudo-elements (#3878)

Co-authored-by: novlan1 <[email protected]>

* feat(SideBarItem): add default slot (#3875)

Co-authored-by: novlan1 <[email protected]>

* fix(image-viewer): 修复背景色错误问题 (#3881)

* chore(docs): regenerate (#3887)

* fix: fix component name error

* chore(docs): regenerate

* chore: update live url (#3886)

---------

Co-authored-by: composable-tu <[email protected]>
Co-authored-by: betavs <[email protected]>
Co-authored-by: novlan1 <[email protected]>
Co-authored-by: wū yāng <[email protected]>
Co-authored-by: liweijie0812 <[email protected]>
anlyyao added a commit that referenced this pull request Aug 29, 2025
* fix(DateTimePicker): 修复在 showWeek 模式下日列表未正确排除 start、end、且 steps 步长不生效的 Bug (#3861)

* fix(DateTimePicker): 修复在 showWeek 模式下日列表未正确排除 start 和 end 的 Bug

* refactor(date-time-picker): 优化日期周显示逻辑,使用统一边界和步长控制

重构 getDaysOfWeekInMonth 方法,使用 getOptionEdge 获取边界值并支持步长配置,简化循环逻辑,移除不必要的日期范围检查

* refactor: use monorepo (#3660)

* chore: directory structure optimization

* chore: update coverage badges

* chore: update dependency installation to use pnpm action

* chore: the respective package.json

* chore: move test to root dir

* chore: update jest config

* chore: update typos-config

* chore: update typos-config

* chore: update import path

* chore: lint

* chore: update script

* chore: update plugin script

* chore: update script

* chore: update deps

* chore: update dep

* chore: support ty live host

* chore: update live host

* chore: update badge script data path

* chore: update vscode setting and nest files

---------

Co-authored-by: novlan1 <[email protected]>

* chore: update group code path (#3880)

* fix(Message): use the correct error theme icon (#3879)

* fix(Message): use the correct error theme icon

* test: update snapshots

---------

Co-authored-by: novlan1 <[email protected]>

* docs: add pkg.pr.new badge (#3882)

* chore(Textarea): using pseudo-elements (#3878)

Co-authored-by: novlan1 <[email protected]>

* feat(SideBarItem): add default slot (#3875)

Co-authored-by: novlan1 <[email protected]>

* fix(image-viewer): 修复背景色错误问题 (#3881)

* chore(docs): regenerate (#3887)

* fix: fix component name error

* chore(docs): regenerate

* chore: update live url (#3886)

* chore: update packageManager to [email protected] (#3889)

* revert live url (#3892)

* chore: revert live url

* chore: update live url and always be outer host

* chore: revert live url

* chore: add m2w.sh (#3893)

* chore: add m2w.sh

* chore: update liveUrl

* chore: use pnpm add

---------

Co-authored-by: composable-tu <[email protected]>
Co-authored-by: betavs <[email protected]>
Co-authored-by: novlan1 <[email protected]>
Co-authored-by: wū yāng <[email protected]>
Co-authored-by: liweijie0812 <[email protected]>
@github-actions github-actions bot mentioned this pull request Oct 20, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

2 participants