INNER CODE UNIT · Go

NextRuntime

asobti/kube-monkey · internal/pkg/calendar/calendar.go:40

func NextRuntime(loc *time.Location, r int) time.Time {
	now := time.Now().In(loc)

	// Is today a weekday and are we still in time for it?
	if isWeekday(now) {
		runtimeToday := time.Date(now.Year(), now.Month(), now.Day(), r, 0, 0, 0, loc)
		if runtimeToday.After(now) {
			return runtimeToday
		}
	}

	// Missed the train for today. Schedule on next weekday
	year, month, day := nextWeekday(loc).Date()
	return time.Date(year, month, day, r, 0, 0, 0, loc)
}

// mtbfPattern matches a whole number with an optional unit, e.g. 3, 3d, 4h or 20m
var mtbfPattern = regexp.MustCompile(`^([0-9]+)([dhm]?)$`)

View source record →

📰 Research Paper
Loading…
⏳ Fetching content…