Skip to content
Open
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
9 changes: 8 additions & 1 deletion parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,12 +135,19 @@ func (p Parser) Parse(spec string) (Schedule, error) {
hour = field(fields[2], hours)
dayofmonth = field(fields[3], dom)
month = field(fields[4], months)
dayofweek = field(fields[5], dow)
dayofweek = field(fields[5], extendedDOW)
)
if err != nil {
return nil, err
}

if 1<<7&dayofweek > 0 {
// For compatibility with https://linux.die.net/man/5/crontab
// we consider 1 in the 7th bit as Sunday and move it to the first bit
dayofweek |= 1
dayofweek ^= 1 << 7
}

return &SpecSchedule{
Second: second,
Minute: minute,
Expand Down
7 changes: 7 additions & 0 deletions parser_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,9 @@ func TestParseSchedule(t *testing.T) {
{secondParser, "CRON_TZ=UTC 0 5 * * * *", every5min(time.UTC)},
{standardParser, "CRON_TZ=UTC 5 * * * *", every5min(time.UTC)},
{secondParser, "CRON_TZ=Asia/Tokyo 0 5 * * * *", every5min(tokyo)},
{standardParser, "CRON_TZ=Asia/Tokyo 0 0 * * 0", everySunday(tokyo)},
{standardParser, "CRON_TZ=Asia/Tokyo 0 0 * * 7", everySunday(tokyo)},
{standardParser, "CRON_TZ=Asia/Tokyo 0 0 * * Sun", everySunday(tokyo)},
{secondParser, "@every 5m", ConstantDelaySchedule{5 * time.Minute}},
{secondParser, "@midnight", midnight(time.Local)},
{secondParser, "TZ=UTC @midnight", midnight(time.UTC)},
Expand Down Expand Up @@ -370,6 +373,10 @@ func midnight(loc *time.Location) *SpecSchedule {
return &SpecSchedule{1, 1, 1, all(dom), all(months), all(dow), loc}
}

func everySunday(loc *time.Location) *SpecSchedule {
return &SpecSchedule{1, 1, 1, all(dom), all(months), 1 << uint(time.Sunday), loc}
}

func annual(loc *time.Location) *SpecSchedule {
return &SpecSchedule{
Second: 1 << seconds.min,
Expand Down
3 changes: 3 additions & 0 deletions spec.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@ var (
"fri": 5,
"sat": 6,
}}

// extendedDOW is only needed to parse "7" as Sunday
extendedDOW = bounds{dow.min, 7, dow.names}
)

const (
Expand Down