func (j *Job) Day() *Job {
	if j.schedule != nil {
		j.err = errors.New("bad function chaining")
	}
	j.schedule = daily{}
	return j
}
Day sets the job to run every day.
package scheduler
import (
	"errors"
	"strconv"
	"strings"
	"sync"
	"time"
)
type scheduled interface {
	nextRun() (time.Duration, error)
}
type Job struct {
	fn        func()
	Quit      chan bool
	SkipWait  chan bool
	err       error
	schedule  scheduled
	isRunning bool
	sync.RWMutex
}
type recurrent struct {
	units  int
	period time.Duration
	done   bool
}
func (r *recurrent) nextRun() (time.Duration, error) {
	if r.units == 0 || r.period == 0 {
		return 0, errors.New("cannot set recurrent time with 0")
	}
	if !r.done {
		r.done = true
		return 0, nil
	}
	return time.Duration(r.units) * r.period, nil
}
type daily struct {
	hour int
	min  int
	sec  int
}
func (d *daily) setTime(h, m, s int) {
	d.hour = h
	d.min = m
	d.sec = s
}
func (d daily) nextRun() (time.Duration, error) {
	now := time.Now()
	year, month, day := now.Date()
	date := time.Date(year, month, day, d.hour, d.min, d.sec, 0, time.Local)
	if now.Before(date) {
		return date.Sub(now), nil
	}
	date = time.Date(year, month, day+1, d.hour, d.min, d.sec, 0, time.Local)
	return date.Sub(now), nil
}
type weekly struct {
	day time.Weekday
	d   daily
}
func (w weekly) nextRun() (time.Duration, error) {
	now := time.Now()
	year, month, day := now.Date()
	numDays := w.day - now.Weekday()
	if numDays == 0 {
		numDays = 7
	} else if numDays < 0 {
		numDays += 7
	}
	date := time.Date(year, month, day+int(numDays), w.d.hour, w.d.min, w.d.sec, 0, time.Local)
	return date.Sub(now), nil
}
func Every(times ...int) *Job {
	switch len(times) {
	case 0:
		return &Job{}
	case 1:
		r := new(recurrent)
		r.units = times[0]
		return &Job{schedule: r}
	default:
		return &Job{err: errors.New("too many arguments in Every")}
	}
}
func (j *Job) NotImmediately() *Job {
	rj, ok := j.schedule.(*recurrent)
	if !ok {
		j.err = errors.New("bad function chaining")
		return j
	}
	rj.done = true
	return j
}
func (j *Job) At(hourTime string) *Job {
	if j.err != nil {
		return j
	}
	hour, min, sec, err := parseTime(hourTime)
	if err != nil {
		j.err = err
		return j
	}
	d, ok := j.schedule.(daily)
	if !ok {
		w, ok := j.schedule.(weekly)
		if !ok {
			j.err = errors.New("bad function chaining")
			return j
		}
		w.d.setTime(hour, min, sec)
		j.schedule = w
	} else {
		d.setTime(hour, min, sec)
		j.schedule = d
	}
	return j
}
func (j *Job) Run(f func()) (*Job, error) {
	if j.err != nil {
		return nil, j.err
	}
	var next time.Duration
	var err error
	j.Quit = make(chan bool, 1)
	j.SkipWait = make(chan bool, 1)
	j.fn = f
	next, err = j.schedule.nextRun()
	if err != nil {
		return nil, err
	}
	go func(j *Job) {
		for {
			select {
			case <-j.Quit:
				return
			case <-j.SkipWait:
				go runJob(j)
			case <-time.After(next):
				go runJob(j)
			}
			next, _ = j.schedule.nextRun()
		}
	}(j)
	return j, nil
}
func (j *Job) setRunning(running bool) {
	j.Lock()
	defer j.Unlock()
	j.isRunning = running
}
func runJob(job *Job) {
	if job.IsRunning() {
		return
	}
	job.setRunning(true)
	job.fn()
	job.setRunning(false)
}
func parseTime(str string) (hour, min, sec int, err error) {
	chunks := strings.Split(str, ":")
	var hourStr, minStr, secStr string
	switch len(chunks) {
	case 1:
		hourStr = chunks[0]
		minStr = "0"
		secStr = "0"
	case 2:
		hourStr = chunks[0]
		minStr = chunks[1]
		secStr = "0"
	case 3:
		hourStr = chunks[0]
		minStr = chunks[1]
		secStr = chunks[2]
	}
	hour, err = strconv.Atoi(hourStr)
	if err != nil {
		return 0, 0, 0, errors.New("bad time")
	}
	min, err = strconv.Atoi(minStr)
	if err != nil {
		return 0, 0, 0, errors.New("bad time")
	}
	sec, err = strconv.Atoi(secStr)
	if err != nil {
		return 0, 0, 0, errors.New("bad time")
	}
	if hour > 23 || min > 59 || sec > 59 {
		return 0, 0, 0, errors.New("bad time")
	}
	return
}
func (j *Job) dayOfWeek(d time.Weekday) *Job {
	if j.schedule != nil {
		j.err = errors.New("bad function chaining")
	}
	j.schedule = weekly{day: d}
	return j
}
func (j *Job) Monday() *Job {
	return j.dayOfWeek(time.Monday)
}
func (j *Job) Tuesday() *Job {
	return j.dayOfWeek(time.Tuesday)
}
func (j *Job) Wednesday() *Job {
	return j.dayOfWeek(time.Wednesday)
}
func (j *Job) Thursday() *Job {
	return j.dayOfWeek(time.Thursday)
}
func (j *Job) Friday() *Job {
	return j.dayOfWeek(time.Friday)
}
func (j *Job) Saturday() *Job {
	return j.dayOfWeek(time.Saturday)
}
func (j *Job) Sunday() *Job {
	return j.dayOfWeek(time.Sunday)
}