任务调度器关于任务执行部分实现(没测没检查, 但应该实现完了)

This commit is contained in:
2025-09-17 20:02:40 +08:00
parent e6047f6b6e
commit ceba0c280e
8 changed files with 392 additions and 36 deletions

View File

@@ -0,0 +1,22 @@
package utils
import (
"time"
"github.com/robfig/cron/v3"
)
// GetNextCronTime 根据传入的 Cron 表达式计算下一次执行的时间。
// 它使用兼容大多数 Cron 实现的标准解析器。
// 如果 Cron 表达式无效,它将返回一个错误。
func GetNextCronTime(cronExpression string) (time.Time, error) {
// cron.ParseStandard() 返回一个支持标准5位或6位带秒格式的解析器。
schedule, err := cron.ParseStandard(cronExpression)
if err != nil {
return time.Time{}, err // 返回零值时间和错误
}
// 从当前时间计算下一次执行时间
nextTime := schedule.Next(time.Now())
return nextTime, nil
}