Skip to content

Commit

Permalink
Accept "/15 * * * *" et al, gh-19
Browse files Browse the repository at this point in the history
  • Loading branch information
jmettraux committed Apr 21, 2019
1 parent ec6b795 commit 42f2917
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 12 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

## fugit 1.1.11 not yet released

* Accept "/15 * * * *" et al, gh-19 and resque/resque-scheduler#649


## fugit 1.1.10 released 2019-04-12

Expand Down
31 changes: 19 additions & 12 deletions lib/fugit/cron.rb
Original file line number Diff line number Diff line change
Expand Up @@ -567,25 +567,32 @@ def sor_mon(i); alt(nil, i, :star, :r_mon); end
def sor_dow(i); alt(nil, i, :star, :r_dow); end

# sorws: star or range with[out] slash
def sorws_mos(i); seq(:elt, i, :sor_mos, :slash, '?'); end
def sorws_hou(i); seq(:elt, i, :sor_hou, :slash, '?'); end
def sorws_dom(i); seq(:elt, i, :sor_dom, :slash, '?'); end
def sorws_mon(i); seq(:elt, i, :sor_mon, :slash, '?'); end
def sorws_dow(i); seq(:elt, i, :sor_dow, :slash, '?'); end
def sorws_mos(i); seq(nil, i, :sor_mos, :slash, '?'); end
def sorws_hou(i); seq(nil, i, :sor_hou, :slash, '?'); end
def sorws_dom(i); seq(nil, i, :sor_dom, :slash, '?'); end
def sorws_mon(i); seq(nil, i, :sor_mon, :slash, '?'); end
def sorws_dow(i); seq(nil, i, :sor_dow, :slash, '?'); end

# ssws: slash or sorws
def mos_elt(i); alt(:elt, i, :slash, :sorws_mos); end
def hou_elt(i); alt(:elt, i, :slash, :sorws_hou); end
def dom_elt(i); alt(:elt, i, :slash, :sorws_dom); end
def mon_elt(i); alt(:elt, i, :slash, :sorws_mon); end
def dow_elt(i); alt(:elt, i, :slash, :sorws_dow); end

def mod(i); rex(:mod, i, /%\d+(\+\d+)?/); end

def mod_dow(i); seq(:elt, i, :dow, :mod); end
def h_dow(i); seq(:elt, i, :dow, :dow_hash); end

def _sorws_dow(i); alt(nil, i, :h_dow, :mod_dow, :sorws_dow); end
def dow_elt_(i); alt(nil, i, :h_dow, :mod_dow, :dow_elt); end

def list_sec(i); jseq(:sec, i, :sorws_mos, :comma); end
def list_min(i); jseq(:min, i, :sorws_mos, :comma); end
def list_hou(i); jseq(:hou, i, :sorws_hou, :comma); end
def list_dom(i); jseq(:dom, i, :sorws_dom, :comma); end
def list_mon(i); jseq(:mon, i, :sorws_mon, :comma); end
def list_dow(i); jseq(:dow, i, :_sorws_dow, :comma); end
def list_sec(i); jseq(:sec, i, :mos_elt, :comma); end
def list_min(i); jseq(:min, i, :mos_elt, :comma); end
def list_hou(i); jseq(:hou, i, :hou_elt, :comma); end
def list_dom(i); jseq(:dom, i, :dom_elt, :comma); end
def list_mon(i); jseq(:mon, i, :mon_elt, :comma); end
def list_dow(i); jseq(:dow, i, :dow_elt_, :comma); end

def lsec_(i); seq(nil, i, :list_sec, :s); end
def lmin_(i); seq(nil, i, :list_min, :s); end
Expand Down
5 changes: 5 additions & 0 deletions spec/cron_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -654,6 +654,11 @@ class Fugit::Cron::TimeCursor
[ '* * * 1 *', '* * * 1 *' ], # and that 01 is a month
[ '* * * 01 *', '* * * 1 *' ], #

[ '*/15 * * * *', '0,15,30,45 * * * *' ], # gh-19
[ '/15 * * * *', '0,15,30,45 * * * *' ], #
[ '/15 * * * * *', '0,15,30,45 * * * * *' ], #
[ '/15 /4 * * *', '0,15,30,45 0,4,8,12,16,20 * * *' ], #

].each { |c, e|
it("parses #{c}") { expect(Fugit::Cron.parse(c).to_cron_s).to eq(e) }
}
Expand Down

0 comments on commit 42f2917

Please sign in to comment.