INNER CODE UNIT · Go
rangeToday
asobti/kube-monkey · internal/pkg/calendar/calendar.go:149
func rangeToday(now time.Time, startHour int, endHour int, loc *time.Location) (start time.Time, remaining time.Duration, full time.Duration) {
now = now.In(loc)
year, month, date := now.Date()
start = time.Date(year, month, date, startHour, 0, 0, 0, loc)
end := time.Date(year, month, date, endHour, 0, 0, 0, loc)
full = end.Sub(start)
if start.Before(now) {
start = now
}
remaining = end.Sub(start)
if full <= 0 || remaining <= 0 {
return start, 0, 0
}
return start, remaining, full
}