Skip to content

[Calendar] 下一月 按钮的显示逻辑有错误 #3986

@manbucy

Description

@manbucy

tdesign-miniprogram 版本

1.10.1

重现链接

No response

重现步骤

Calendar 组件设置:
value=new Date(2025, 9, 11);
min-date = new Date(2025, 8, 11); ,
max-date = new Date(2025, 10, 11);
switch-mode=month;

  1. 点击日历上的10月31号,会发现下一个月的按钮无法点击。

期望结果

下一个月的按钮可点击,因为当前仍然处于10月,且最大日期时11月11日。

实际结果

下一月按钮无法点击

基础库版本

No response

补充说明

具体原因为getMonthByOffset 方法有问题。
假设 Date value = new Date(yyyy, mm, dd);
getMonthByOffset(value, n);
如果value + n 月那一天没有 dd, 则会自动进入下一个月,也就是value+n+1.

https://github.com/Tencent/tdesign-miniprogram/blob/develop/packages/components/calendar/utils.ts

function getMonthByOffset(t, e) {
  const n = new Date(t);
  return n.setMonth(n.getMonth() + e), n.setDate(1), n;
}

getMonthByOffset 计算结果有误。

getMonthByOffset(new Date(2025, 9, 30), 1)  --> Sat Nov 01 2025 00:00:00 GMT+0800 (China Standard Time)
getMonthByOffset(new Date(2025, 9, 31), 1)  --> Mon Dec 01 2025 00:00:00 GMT+0800 (China Standard Time)

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions