Skip to content

Commit

Permalink
fixed validation
Browse files Browse the repository at this point in the history
  • Loading branch information
subhashish-devtron committed Jun 25, 2024
1 parent f4daf26 commit 8d9fbbc
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions timeRangeLib/validator.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,16 @@ func (tr TimeRange) ValidateTimeRange() error {
}

}

if !tr.TimeFrom.IsZero() && !tr.TimeTo.IsZero() {
if tr.TimeFrom.After(tr.TimeTo) {
return errors.New(string(TimeFromLessThanTimeTo))
}
if tr.TimeFrom.Equal(tr.TimeTo) {
return errors.New(string(TimeFromEqualToTimeTo))
}
}

switch tr.Frequency {
case Daily:
if tr.HourMinuteFrom == "" || tr.HourMinuteTo == "" {
Expand All @@ -31,12 +41,6 @@ func (tr TimeRange) ValidateTimeRange() error {
if tr.TimeFrom.IsZero() || tr.TimeTo.IsZero() {
return errors.New(string(TimeFromOrToNotPresent))
}
if tr.TimeFrom.After(tr.TimeTo) {
return errors.New(string(TimeFromLessThanTimeTo))
}
if tr.TimeFrom.Equal(tr.TimeTo) {
return errors.New(string(TimeFromEqualToTimeTo))
}
case Weekly:
if len(tr.Weekdays) == 0 {
return errors.New(string(WeekDaysNotPresent))
Expand Down

0 comments on commit 8d9fbbc

Please sign in to comment.