Skip to content

Commit

Permalink
regex for at time accepts time without leading zeros (#56)
Browse files Browse the repository at this point in the history
  • Loading branch information
JohnRoesler authored Sep 8, 2020
1 parent 25952fd commit e40f9c8
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 2 deletions.
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,12 @@ func main() {
s2.Every(1).Month(time.Now().Day()).Do(task)
s2.Every(2).Months(15).Do(task)

// check for errors
_, err := s2.Every(1).Day().At("bad-time").Do(task)
if err != nil {
log.Fatalf("error creating job: %v", err)
}

// Do jobs with params
s2.Every(1).Second().Do(taskWithParams, 1, "hello")

Expand All @@ -80,6 +86,7 @@ func main() {
s2.Every(1).Day().At("10:30").Do(task)
s2.Every(1).Monday().At("18:30").Do(task)
s2.Every(1).Tuesday().At("18:30:59").Do(task)
s2.Every(1).Wednesday().At("1:01").Do(task)

// Begin job at a specific date/time.
// Attention: scheduler timezone has precedence over job's timezone!
Expand Down
4 changes: 2 additions & 2 deletions gocron.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ var (

// regex patterns for supported time formats
var (
timeWithSeconds = regexp.MustCompile(`(?m)^\d\d:\d\d:\d\d$`)
timeWithoutSeconds = regexp.MustCompile(`(?m)^\d\d:\d\d$`)
timeWithSeconds = regexp.MustCompile(`(?m)^\d{1,2}:\d\d:\d\d$`)
timeWithoutSeconds = regexp.MustCompile(`(?m)^\d{1,2}:\d\d$`)
)

type timeUnit int
Expand Down
15 changes: 15 additions & 0 deletions gocron_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,13 @@ func TestFormatTime(t *testing.T) {
wantMin: 18,
wantErr: false,
},
{
name: "normal - no leading hour zeros",
args: "6:08",
wantHour: 6,
wantMin: 8,
wantErr: false,
},
{
name: "normal_with_second",
args: "06:18:01",
Expand All @@ -32,6 +39,14 @@ func TestFormatTime(t *testing.T) {
wantSec: 1,
wantErr: false,
},
{
name: "normal_with_second - no leading hour zeros",
args: "6:08:01",
wantHour: 6,
wantMin: 8,
wantSec: 1,
wantErr: false,
},
{
name: "not_a_number",
args: "e:18",
Expand Down

0 comments on commit e40f9c8

Please sign in to comment.