Skip to content

Commit

Permalink
fix: support for cron with dual hour ranges (#70)
Browse files Browse the repository at this point in the history
  • Loading branch information
shreddedbacon authored Sep 9, 2024
1 parent 5a79dc5 commit 8ee7004
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
10 changes: 10 additions & 0 deletions utils/cron/cron.go
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,16 @@ func ConvertCrontab(namespace, cron string) (string, error) {
hours = val
continue
}
sVal := strings.Split(val, ",")
if len(sVal) > 1 {
fmt.Println(sVal)
for _, r := range sVal {
if isInRange(r, 0, 23) {
continue
}
}
hours = val
}
// if the value is not valid, return an error with where the issue is
if hours == "" {
return "", fmt.Errorf("cron definition '%s' is invalid, unable to determine hours value", cron)
Expand Down
8 changes: 8 additions & 0 deletions utils/cron/cron_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,14 @@ func TestConvertCrontab(t *testing.T) {
wantErrMsg: "cron definition '*/1 * * * * 7' is invalid, 6 fields provided, required 5",
wantErr: true,
},
{
name: "test22 - split range hours",
args: args{
namespace: "example-com-main",
cron: "*/30 0-12,22-23 * * *",
},
want: "1,31 0-12,22-23 * * *",
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
Expand Down

0 comments on commit 8ee7004

Please sign in to comment.