Skip to content

【修复】cron表达式中day-of-month使用L时会跳过非31天的月份(ISSUE-3722),以及使用W最近工作日时解析未正确处理周末和月份边界情况 #3743

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

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

wankaiyi
Copy link
Contributor

@wankaiyi wankaiyi commented Jun 29, 2025

What kind of change does this PR introduce?

  • Bugfix
  • Feature
  • Code style update
  • Refactor
  • Build-related changes
  • Other, please describe:

The description of the PR:

  1. day-of-month使用L的时候,会跳过非31天的月份
  • 错误描述:根据cron表达式计算任务的下一次执行时间时,如果cron表达式中的日期包含L(本月最后一天),则计算出来的下一次执行时间会跳过非31天的月份,会影响到任务的执行。
  • 错误原因:在计算本月最后一天时,将非31天月份的日期设置为31,导致Calendar自动将月份+1而跳过非31天的月份。
  • 效果:
    修复前
    image
    修复后
    image

Resolves #3722

  1. day-of-month使用W最近工作日解析未正确处理周末和月份边界情况
  • 错误描述:根据cron表达式计算任务的下一次执行时间时,如果cron表达式中的日期为类似10W时,会跳过最近工作日大于指定日期的月份
  • 错误原因:计算smallestDayForWeekday时没有正确处理周末和月份边界情况,导致认为没有找到正确的日期而让月份+1
  • 效果:
    修复前
    image
    修复后
    image

添加了覆盖常用使用场景和边界的单元测试对其他类型的cron表达式的解析进行测试,兼容历史版本。

@wankaiyi wankaiyi changed the title 【修复】cron表达式中day-of-month使用L的时候,会跳过非31天的月份(ISSUE-3722) 【修复】cron表达式中day-of-month使用L的时候,会跳过非31天的月份(ISSUE-3722)以及W最近工作日解析未正确处理周末和月份边界情况 Jul 5, 2025
@wankaiyi wankaiyi changed the title 【修复】cron表达式中day-of-month使用L的时候,会跳过非31天的月份(ISSUE-3722)以及W最近工作日解析未正确处理周末和月份边界情况 【修复】cron表达式中day-of-month使用L的时候,会跳过非31天的月份(ISSUE-3722)以及使用W最近工作日解析未正确处理周末和月份边界情况 Jul 5, 2025
@wankaiyi wankaiyi changed the title 【修复】cron表达式中day-of-month使用L的时候,会跳过非31天的月份(ISSUE-3722)以及使用W最近工作日解析未正确处理周末和月份边界情况 【修复】cron表达式中day-of-month使用L时会跳过非31天的月份(ISSUE-3722),以及使用W最近工作日时解析未正确处理周末和月份边界情况 Jul 5, 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
Development

Successfully merging this pull request may close these issues.

CRON表达式0 0 18 L * ? 每月最后一个工作日18点执行问题
1 participant