Skip to content

Conversation

@cyfung1031
Copy link
Collaborator

@cyfung1031 cyfung1031 commented Jan 2, 2026

概述 Descriptions

  1. 修正 getWeek 为 getISOWeek, 详见 修正 getISOWeek #1124
  2. nextTime 增加 i18n, 修正计算方法 (使用 cron 内部的 luxon DateTime 简化偏移计算代码)
  3. 加入更多单元测试
  4. 增强 once 表达式处理
  5. crontabExec 引入 timeDiff 修正执行时间判断
  6. 升级 cron 至 4.4.0

增强 once 表达式处理

现时只有 once -> * 做法
假如开发者只想在某几天运行一次, 现在做不到
因此引入以下写法

@cronjob * 19-22 once(11,21,31) * *
在11日,21日,31日,一天只执行一次。

@cronjob * 21 once(6-17) * *
在6-17日,晚上9时,一天只执行一次。

  • 旧写法等价于 once(*)

crontabExec 引入 timeDiff 修正执行时间判断

flag = last.getHours() !== now.getHours(); 这种写法存在问题
你假设了连续运行
假如脚本在 星期一 8:23分执行了
然后8:25分关掉电脑
再在 星期二 8:17分打开电脑
这样 last.getHours() !== now.getHours() 就会判断为 false, 导致错误地没有执行

升级 cron 至 4.4.0

  • 3.x.x 升至 4.x.x 的 breaking change, ScriptCat 没有使用相关 breaking change, 因此不影响,可以直接升级
  • 似乎修正了一些计时器相关的问题。旧 issue 可能因此解决

cron 内部有 luxon. 如有需要,可以在 package.json 加 luxon,使代码好看一点

const DateTime = new CronTime("* * * * *").sendAt().constructor;

可改成

import { DateTime } from "luxon";

@cyfung1031 cyfung1031 changed the base branch from main to release/v1.3 January 2, 2026 17:55
@cyfung1031 cyfung1031 changed the title Cron nexTime 相关修改 [v1.3] Cron nexTime 相关修改 Jan 2, 2026
@cyfung1031 cyfung1031 changed the title [v1.3] Cron nexTime 相关修改 [v1.3] Cron 相关修改:bug 修补、i18n、once 表达式增强、升级 cron 库 Jan 2, 2026
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.

1 participant