diff --git a/go.mod b/go.mod index 36ba574..1461dbf 100644 --- a/go.mod +++ b/go.mod @@ -24,6 +24,8 @@ require ( sigs.k8s.io/controller-runtime v0.13.1 ) +replace github.com/robfig/cron/v3 v3.0.1 => github.com/juliev0/cron/v3 v3.0.2-0.20220310063235-7181f74c09e9 // https://github.com/robfig/cron/pull/437 + require ( cloud.google.com/go v0.97.0 // indirect github.com/Azure/go-autorest v14.2.0+incompatible // indirect diff --git a/go.sum b/go.sum index e7682eb..b485bd3 100644 --- a/go.sum +++ b/go.sum @@ -245,6 +245,8 @@ github.com/jstemmer/go-junit-report v0.0.0-20190106144839-af01ea7f8024/go.mod h1 github.com/jstemmer/go-junit-report v0.9.1/go.mod h1:Brl9GWCQeLvo8nXZwPNNblvFj/XSXhF0NWZEnDohbsk= github.com/julienschmidt/httprouter v1.2.0/go.mod h1:SYymIcj16QtmaHHD7aYtjjsJG7VTCxuUUipMqKk8s4w= github.com/julienschmidt/httprouter v1.3.0/go.mod h1:JR6WtHb+2LUe8TCKY3cZOxFyyO8IZAc4RVcycCCAKdM= +github.com/juliev0/cron/v3 v3.0.2-0.20220310063235-7181f74c09e9 h1:Pa9SanmckPLZ4HeHEl/OGxXPKRg5NpNx3xmM8wDN/LE= +github.com/juliev0/cron/v3 v3.0.2-0.20220310063235-7181f74c09e9/go.mod h1:eQICP3HwyT7UooqI/z+Ov+PtYAWygg1TEWWzGIFLtro= github.com/kisielk/errcheck v1.5.0/go.mod h1:pFxgyoBC7bSaBwPgfKdkLd5X25qrDl4LWUI2bnpBCr8= github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck= github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ= @@ -310,8 +312,6 @@ github.com/prometheus/procfs v0.1.3/go.mod h1:lV6e/gmhEcM9IjHGsFOCxxuZ+z1YqCvr4O github.com/prometheus/procfs v0.6.0/go.mod h1:cz+aTbrPOrUb4q7XlbU9ygM+/jj0fzG6c1xBZuNvfVA= github.com/prometheus/procfs v0.7.3 h1:4jVXhlkAyzOScmCkXBTOLRLTz8EeU+eyjrwB/EPq0VU= github.com/prometheus/procfs v0.7.3/go.mod h1:cz+aTbrPOrUb4q7XlbU9ygM+/jj0fzG6c1xBZuNvfVA= -github.com/robfig/cron/v3 v3.0.1 h1:WdRxkvbJztn8LMz/QEvLN5sBU+xKpSqwwUO1Pjr4qDs= -github.com/robfig/cron/v3 v3.0.1/go.mod h1:eQICP3HwyT7UooqI/z+Ov+PtYAWygg1TEWWzGIFLtro= github.com/rogpeppe/fastuuid v1.2.0/go.mod h1:jVj6XXZzXRy/MSR5jhDC/2q6DgLz+nrA6LYCDYWNEvQ= github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4= github.com/sirupsen/logrus v1.2.0/go.mod h1:LxeOpSwHxABJmUn/MG1IvRgCAasNZTLOkJPxbbu5VWo= diff --git a/utils/cron/cron.go b/utils/cron/cron.go deleted file mode 100644 index 9822f5e..0000000 --- a/utils/cron/cron.go +++ /dev/null @@ -1,36 +0,0 @@ -package cron - -import ( - "time" - - "github.com/robfig/cron/v3" -) - -type Schedule interface { - Previous(time.Time) time.Time - Next(time.Time) time.Time -} - -type schedule struct { - cron.Schedule -} - -func ParseStandard(standardSpec string) (Schedule, error) { - s, err := cron.ParseStandard(standardSpec) - if err != nil { - return nil, err - } - return &schedule{Schedule: s}, nil -} - -func (s *schedule) Previous(t time.Time) time.Time { - // Iterate backwards to find the previous time - prevTime := t - for { - prevNextTime := s.Next(prevTime) - if prevNextTime.Before(t) { - return prevNextTime - } - prevTime = prevTime.Add(-time.Minute) - } -} diff --git a/utils/timerange/cron.go b/utils/timerange/cron.go index 4bd8eef..7871dc8 100644 --- a/utils/timerange/cron.go +++ b/utils/timerange/cron.go @@ -6,7 +6,7 @@ import ( "strings" "time" - "github.com/xscaling/wing/utils/cron" + "github.com/robfig/cron/v3" ) var ( @@ -70,7 +70,7 @@ func NewCronScheduler(timezone *time.Location, start, end string) (*CronSchedule func (s *CronScheduler) Contains(when time.Time) bool { whenInTimezone := when.In(s.timezone) - lastStart := s.startSched.Previous(whenInTimezone) + lastStart := s.startSched.Prev(whenInTimezone) nextStart := s.startSched.Next(whenInTimezone) nextEnd := s.endSched.Next(whenInTimezone) // when in [lastStart, nextEnd) and nextStart > nextEnd