func (w *WindowedScheduleResponse) LastTime() time.Time {
	return w.lastTime
}
LastTime returns the last windowed schedule response time
package schedule
import (
	"time"
	log "github.com/sirupsen/logrus"
)
var (
	logger = log.WithField("_module", "schedule")
)
type WindowedSchedule struct {
	Interval   time.Duration
	StartTime  *time.Time
	StopTime   *time.Time
	Count      uint
	state      ScheduleState
	stopOnTime *time.Time
}
func NewWindowedSchedule(i time.Duration, start *time.Time, stop *time.Time, count uint) *WindowedSchedule {
	if count != 0 && stop != nil {
		count = 0
		logger.WithFields(log.Fields{
			"_block": "NewWindowedSchedule",
		}).Warning("The window stop timestamp and the count cannot be specified simultaneously. The parameter `count` has been ignored.")
	}
	return &WindowedSchedule{
		Interval:  i,
		StartTime: start,
		StopTime:  stop,
		Count:     count,
	}
}
func (w *WindowedSchedule) setStopOnTime() {
	if w.StopTime == nil && w.Count != 0 {
		var newStop time.Time
		if w.StartTime != nil && time.Now().Before(*w.StartTime) {
			newStop = w.StartTime.Add(time.Duration(w.Count) * w.Interval)
		} else {
			newStop = time.Now().Add(time.Duration(w.Count) * w.Interval)
		}
		w.stopOnTime = &newStop
		return
	}
	w.stopOnTime = w.StopTime
}
func (w *WindowedSchedule) GetState() ScheduleState {
	return w.state
}
func (w *WindowedSchedule) Validate() error {
	if w.StopTime != nil && time.Now().After(*w.StopTime) {
		return ErrInvalidStopTime
	}
	if w.StopTime != nil && w.StartTime != nil && w.StopTime.Before(*w.StartTime) {
		return ErrStopBeforeStart
	}
	if w.Interval <= 0 {
		return ErrInvalidInterval
	}
	w.state = Active
	return nil
}
func (w *WindowedSchedule) Wait(last time.Time) Response {
	var m uint
	if (last == time.Time{}) {
		w.setStopOnTime()
	}
	if w.StartTime != nil {
		if time.Now().Before(*w.StartTime) {
			wait := w.StartTime.Sub(time.Now())
			logger.WithFields(log.Fields{
				"_block":         "windowed-wait",
				"sleep-duration": wait,
			}).Debug("Waiting for window to start")
			time.Sleep(wait)
		}
	}
	if w.stopOnTime != nil {
		if time.Now().Before(*w.stopOnTime) {
			logger.WithFields(log.Fields{
				"_block":           "windowed-wait",
				"time-before-stop": w.stopOnTime.Sub(time.Now()),
			}).Debug("Within window, calling interval")
			m, _ = waitOnInterval(last, w.Interval)
			if time.Now().After(*w.stopOnTime) {
				logger.WithFields(log.Fields{
					"_block": "windowed-wait",
				}).Debug("schedule has ended")
				w.state = Ended
			}
		} else {
			logger.WithFields(log.Fields{
				"_block": "windowed-wait",
			}).Debug("schedule has ended")
			w.state = Ended
			m = 0
		}
	} else {
		m, _ = waitOnInterval(last, w.Interval)
	}
	return &WindowedScheduleResponse{
		state:    w.GetState(),
		missed:   m,
		lastTime: time.Now(),
	}
}
type WindowedScheduleResponse struct {
	state    ScheduleState
	missed   uint
	lastTime time.Time
}
func (w *WindowedScheduleResponse) State() ScheduleState {
	return w.state
}
func (w *WindowedScheduleResponse) Error() error {
	return nil
}
func (w *WindowedScheduleResponse) Missed() uint {
	return w.missed
}