From 0f83cb5e66f16f879c2cc5f08e3ecae65f799b57 Mon Sep 17 00:00:00 2001 From: huangsimin Date: Fri, 4 Jan 2019 18:24:41 +0800 Subject: [PATCH] =?UTF-8?q?=E8=B0=83=E6=95=B4=E6=AD=A3=E7=A1=AE=E7=9A=84?= =?UTF-8?q?=E7=BB=9F=E8=AE=A1=E8=AE=A9=E7=AC=AC=E4=B8=80=E6=AC=A1=E7=9B=B4?= =?UTF-8?q?=E6=8E=A5=E6=89=A7=E8=A1=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- crontab.go | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/crontab.go b/crontab.go index 7d7a424..e6d3946 100644 --- a/crontab.go +++ b/crontab.go @@ -185,12 +185,14 @@ func (cron *Crontab) FromString(crontab string) error { // "f1-2|5-10x5,f1|10m,10-15,f1" cron.lastStatus = true - cron.isCalculated = false + cron.isCalculated = true + cron.nextTime = time.Now() + cron.interval = clinked.NewCircularLinked() var intervalList []interface{} intervalList = parseIntervalString(matches[0]) cron.interval.Append(intervalList...) - cron.TimeUp() + case 5: cron.min = createTimePointer(matches[0], 0, 59, true) cron.hour = createTimePointer(matches[1], 0, 23, true) @@ -328,7 +330,7 @@ func (cron *Crontab) intervalCalculateNextTime(now time.Time) { func (cron *Crontab) intervalTimeUp() bool { - if cron.isCalculated != false { + if cron.isCalculated { // 需要调用nexttime()才能正常正常计算下次的时间 now := time.Now() if now.Unix() >= cron.nextTime.Unix() { cron.isCalculated = false