Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Allow Leading Zeroes in Cron #116

Merged
merged 1 commit into from
Feb 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 9 additions & 9 deletions cronexpr/cronexpr_parse.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,15 +76,15 @@ var (
"2090": 2090, "2091": 2091, "2092": 2092, "2093": 2093, "2094": 2094, "2095": 2095, "2096": 2096, "2097": 2097, "2098": 2098, "2099": 2099,
}
monthTokens = map[string]int{
`1`: 1, `jan`: 1, `january`: 1,
`2`: 2, `feb`: 2, `february`: 2,
`3`: 3, `mar`: 3, `march`: 3,
`4`: 4, `apr`: 4, `april`: 4,
`5`: 5, `may`: 5,
`6`: 6, `jun`: 6, `june`: 6,
`7`: 7, `jul`: 7, `july`: 7,
`8`: 8, `aug`: 8, `august`: 8,
`9`: 9, `sep`: 9, `september`: 9,
`01`: 1, `1`: 1, `jan`: 1, `january`: 1,
`02`: 2, `2`: 2, `feb`: 2, `february`: 2,
`03`: 3, `3`: 3, `mar`: 3, `march`: 3,
`04`: 4, `4`: 4, `apr`: 4, `april`: 4,
`05`: 5, `5`: 5, `may`: 5,
`06`: 6, `6`: 6, `jun`: 6, `june`: 6,
`07`: 7, `7`: 7, `jul`: 7, `july`: 7,
`08`: 8, `8`: 8, `aug`: 8, `august`: 8,
`09`: 9, `9`: 9, `sep`: 9, `september`: 9,
`10`: 10, `oct`: 10, `october`: 10,
`11`: 11, `nov`: 11, `november`: 11,
`12`: 12, `dec`: 12, `december`: 12,
Expand Down
17 changes: 16 additions & 1 deletion cronexpr/cronexpr_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,16 @@ var crontests = []crontest{
},
},

// Check that month is allowed a zero prefix (should correctly land in february in subsequent year)
{
"0 0 28 02 * *",
"Mon 2006-01-02 15:04",
[]crontimes{
{"2013-09-02 00:00:00", "Fri 2014-02-28 00:00"},
{"2014-08-15 00:00:00", "Sat 2015-02-28 00:00"},
},
},

// TODO: more tests
}

Expand Down Expand Up @@ -230,7 +240,12 @@ func TestZero(t *testing.T) {

next = MustParse("* * * * * 2099").Next(time.Time{})
if next.IsZero() == false {
t.Error(`("* * * * * 2014").Next(time.Time{}).IsZero() returned 'true', expected 'false'`)
t.Error(`("* * * * * 2099").Next(time.Time{}).IsZero() returned 'true', expected 'false'`)
}

next = MustParse("11 1 31 2 * *").Next(time.Time{})
if next.IsZero() == false {
t.Error(`("11 1 31 2 * *").Next(time.Time{}).IsZero() returned 'true', expected 'false'`)
}
}

Expand Down