// durationToNextRun calculate how much time to the next run, depending on unit
durationToNextRun calculate how much time to the next run, depending on unit
// durationToNextRun calculate how much time to the next run depending on unit
func (s *Scheduler) durationToNextRun(lastRun time.Time, job *Job) time.Duration {
	if job.getStartAtTime().After(lastRun) {
		return job.getStartAtTime().Sub(s.now())
	}
	var d time.Duration
	switch job.getUnit() {
	case milliseconds, seconds, minutes, hours:
		d = s.calculateDuration(job)
	case days:
		d = s.calculateDays(job, lastRun)
	case weeks:
		if len(job.scheduledWeekday) != 0 { 
			d = s.calculateWeekday(job, lastRun)
		} else {
			d = s.calculateWeeks(job, lastRun)
		}
	case months:
		d = s.calculateMonths(job, lastRun)
	case duration:
		d = job.getDuration()
	case crontab:
		d = job.cronSchedule.Next(lastRun).Sub(lastRun)
	}
	return d
}
func ( s * Scheduler ) durationToNextRun ( lastRun time . Time , job * Job ) time . Duration { if job . getStartAtTime ( ) . After ( lastRun ) { return job . getStartAtTime ( ) . Sub ( s . now ( ) ) } var d time . Duration switch job . getUnit ( ) { case milliseconds , seconds , minutes , hours : d = s . calculateDuration ( job ) case days : d = s . calculateDays ( job , lastRun ) case weeks : if len ( job . scheduledWeekday ) != 0 { d = s . calculateWeekday ( job , lastRun ) } else { d = s . calculateWeeks ( job , lastRun ) } case months : d = s . calculateMonths ( job , lastRun ) case duration : d = job . getDuration ( ) case crontab : d = job . cronSchedule . Next ( lastRun ) . Sub ( lastRun ) } return d }
durationToNextRun calculate how much time to the next run, depending on unit
durationToNextRun calculate how much time to the next run depending on unit
// job can be scheduled with .StartAt() // weekday selected, Every().Monday(), for example