-
Notifications
You must be signed in to change notification settings - Fork 354
feat(calendar): add function to support setting start or end of range separately #2347
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: develop
Are you sure you want to change the base?
Conversation
There was a problem hiding this 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 adds support for setting calendar range boundaries independently by enhancing the range parameter handling in the calendar component. It allows users to specify only a start date (using a fallback for the end) or only an end date (using a fallback for the start), rather than requiring both boundaries to be valid dates.
Key changes:
- New utility function
handleRangeprocesses range inputs with flexible boundary validation, using fallback values (1970-01-01 for start, current date for end) when one boundary is invalid - New type definitions (
CalendarValue,CalendarRange) to support string or Date formats for calendar ranges - Comprehensive test suite with 100% coverage for the new utility functions
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| js/calendar/types.ts | Defines CalendarValue and CalendarRange types to support string or Date range boundaries |
| js/calendar/consts.ts | Exports MIN_YEAR constant (1970) used as fallback for undefined start boundary |
| js/calendar/utils.ts | Implements handleRange function with boundary validation, fallback logic, and automatic swapping for out-of-order dates |
| test/unit/calendar/utils.test.js | Adds comprehensive test coverage for createDefaultCurDate and handleRange functions across all scenarios |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
🤔 这个 PR 的性质是?
🔗 相关 Issue
💡 需求背景和解决方案
单独设置日历范围上/下限本质上为完善对
range参数传入值的数据处理,即处理以下情况:以上核心在于判断列表值的两项是否符合日期格式,故首先增加了一个日期格式校验逻辑
然后在解构出列表值的两项后先进行日期格式校验即可直接处理第一种情况。
随后添加
fallback逻辑,当出现第二种情况时,为空缺的另外一侧边界填充内置值;若为第三种情况则保持原逻辑不变📝 更新日志
feat(calendar): 新增
calendar组件的公用类型和公用常量feat(calendar): 新增
range参数处理函数以支持单独设置日历范围上限或下限test(calendar): 新增
createDefaultCurDate和handleRange的测试案例并提升覆盖率至100%本条 PR 不需要纳入 Changelog
☑️ 请求合并前的自查清单