github.com/ngicks/gokugen@v0.0.5/cron/dur.go (about) 1 package cron 2 3 import "time" 4 5 // Duration implements same RowLike interface as Row. 6 type Duration struct { 7 Duration time.Duration `json:"duration"` 8 Command []string `json:"command"` 9 } 10 11 func (d Duration) IsCommandValid() bool { 12 return d.Command != nil && len(d.Command) != 0 13 } 14 15 // NextSchedule returns now + Duration. 16 func (d Duration) NextSchedule(now time.Time) (time.Time, error) { 17 return now.Add(d.Duration), nil 18 } 19 20 // GetCommand returns []string if Command is valid, nil otherwise. 21 // Mutating returned slice causes undefined behavior. 22 func (d Duration) GetCommand() []string { 23 if d.IsCommandValid() { 24 return d.Command 25 } else { 26 return nil 27 } 28 }