Skip to content

Commit

Permalink
cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
bennsimon committed Aug 10, 2023
1 parent 72f32ce commit 8ec40b4
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions handler/scheduleHandler/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,12 @@ func (s *ScheduleHandler) ValidateSchedule(schedule *workloadschedulerv1.Schedul
return fmt.Errorf("schedule(s) need to be defined")
} else {
now := time.Now().In(time.Local)
longDayNames := []string{"sunday", "monday", "tuesday", "wednesday", "thursday", "friday", "saturday"}
days := []string{"sunday", "monday", "tuesday", "wednesday", "thursday", "friday", "saturday"}

for _, scheduleUnit := range schedule.Spec.ScheduleUnits {
if scheduleUnit.Days != nil && len(scheduleUnit.Days) > 0 {
for _, day := range scheduleUnit.Days {
if !slices.Contains(longDayNames, strings.ToLower(day)) {
if !slices.Contains(days, strings.ToLower(day)) {
return fmt.Errorf("day: %s, is not valid", day)
}
}
Expand All @@ -50,8 +50,11 @@ func (s *ScheduleHandler) ValidateSchedule(schedule *workloadschedulerv1.Schedul
return err
}

if startTime.After(endTime) || startTime.Equal(endTime) {
return fmt.Errorf("invalid timeunit; startTime: %s, endTime: %s", startTime, endTime)
if startTime.After(endTime) {
return fmt.Errorf("invalid timeunit, %s; startTime: %s, endTime: %s", "endTime is before startTime", startTime, endTime)
}
if startTime.Equal(endTime) {
return fmt.Errorf("invalid timeunit, %s; startTime: %s, endTime: %s", "endTime == startTime", startTime, endTime)
}
}
}
Expand Down

0 comments on commit 8ec40b4

Please sign in to comment.