From 092771ebd811c2ae6ad779adf17383f9fb7a1f97 Mon Sep 17 00:00:00 2001 From: Yun Date: Mon, 1 Dec 2025 13:40:31 +0800 Subject: [PATCH] =?UTF-8?q?=E9=97=B4=E9=9A=94=E7=9A=84base=E4=B8=BA?= =?UTF-8?q?=E5=9B=BA=E5=AE=9A=E7=9A=842025=E5=B9=B4=E5=BC=80=E5=A7=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- cluster.go | 10 ++++------ single.go | 10 ++++------ 2 files changed, 8 insertions(+), 12 deletions(-) diff --git a/cluster.go b/cluster.go index 6fcc135..a3f0721 100644 --- a/cluster.go +++ b/cluster.go @@ -352,15 +352,14 @@ func (c *Cluster) EveryMinute(ctx context.Context, taskId string, second int, ca // 特定时间间隔 func (c *Cluster) EverySpace(ctx context.Context, taskId string, spaceTime time.Duration, callback func(ctx context.Context, extendData interface{}) error, extendData interface{}) error { - nowTime := time.Now().In(c.location) if spaceTime < 0 { c.logger.Errorf(ctx, "间隔时间不能小于0") return errors.New("间隔时间不能小于0") } - // 获取当天的零点时间 - zeroTime := time.Date(nowTime.Year(), nowTime.Month(), nowTime.Day(), 0, 0, 0, 0, nowTime.Location()) + // 固定时间点为20250101 00:00:00,便于计算下一次执行时间 + zeroTime := time.Date(2025, 1, 1, 0, 0, 0, 0, c.location) jobData := JobData{ JobType: JobTypeInterval, @@ -381,9 +380,8 @@ func (c *Cluster) EverySpace(ctx context.Context, taskId string, spaceTime time. // @param extendData interface{} 扩展数据 // @return error func (l *Cluster) Cron(ctx context.Context, taskId string, cronExpression string, callback func(ctx context.Context, extendData any) error, extendData any, opt ...Option) error { - nowTime := time.Now().In(l.location) - // 获取当天的零点时间 - zeroTime := time.Date(nowTime.Year(), nowTime.Month(), nowTime.Day(), 0, 0, 0, 0, nowTime.Location()) + // 固定时间点为20250101 00:00:00,便于计算下一次执行时间 + zeroTime := time.Date(2025, 1, 1, 0, 0, 0, 0, l.location) options := newEmptyOptions(opt...) cronParser := l.cronParser diff --git a/single.go b/single.go index 51b82ee..01a6333 100644 --- a/single.go +++ b/single.go @@ -252,15 +252,14 @@ func (c *Single) EveryMinute(ctx context.Context, taskId string, second int, cal // 特定时间间隔 func (c *Single) EverySpace(ctx context.Context, taskId string, spaceTime time.Duration, callback func(ctx context.Context, extendData interface{}) error, extendData interface{}) (int64, error) { - nowTime := time.Now().In(c.location) if spaceTime < 0 { c.logger.Errorf(ctx, "间隔时间不能小于0") return 0, ErrIntervalTime } - // 获取当天的零点时间 - zeroTime := time.Date(nowTime.Year(), nowTime.Month(), nowTime.Day(), 0, 0, 0, 0, nowTime.Location()) + // 固定时间点为20250101 00:00:00,便于计算下一次执行时间 + zeroTime := time.Date(2025, 1, 1, 0, 0, 0, 0, c.location) jobData := JobData{ JobType: JobTypeInterval, @@ -274,9 +273,8 @@ func (c *Single) EverySpace(ctx context.Context, taskId string, spaceTime time.D } func (l *Single) Cron(ctx context.Context, taskId string, cronExpression string, callback func(ctx context.Context, extendData any) error, extendData any, opt ...Option) (int64, error) { - nowTime := time.Now().In(l.location) - // 获取当天的零点时间 - zeroTime := time.Date(nowTime.Year(), nowTime.Month(), nowTime.Day(), 0, 0, 0, 0, nowTime.Location()) + // 固定时间点为20250101 00:00:00,便于计算下一次执行时间 + zeroTime := time.Date(2025, 1, 1, 0, 0, 0, 0, l.location) options := Options{} for _, o := range opt {