Skip to content

Commit

Permalink
Accept extra commas in cron notation, gh-77
Browse files Browse the repository at this point in the history
  • Loading branch information
jmettraux committed Sep 14, 2022
1 parent e8da0f9 commit 052cfde
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 7 deletions.
15 changes: 8 additions & 7 deletions lib/fugit/cron.rb
Original file line number Diff line number Diff line change
Expand Up @@ -660,7 +660,8 @@ module Parser include Raabro
def s(i); rex(nil, i, /[ \t]+/); end
def star(i); str(nil, i, '*'); end
def hyphen(i); str(nil, i, '-'); end
def comma(i); str(nil, i, ','); end
def comma(i); rex(nil, i, /,([ \t]*,)*/); end
def comma?(i); rex(nil, i, /([ \t]*,)*/); end

def slash(i); rex(:slash, i, /\/\d\d?/); end

Expand Down Expand Up @@ -720,12 +721,12 @@ 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
def lhou_(i); seq(nil, i, :list_hou, :s); end
def ldom_(i); seq(nil, i, :list_dom, :s); end
def lmon_(i); seq(nil, i, :list_mon, :s); end
alias ldow list_dow
def lsec_(i); seq(nil, i, :comma, '?', :list_sec, :comma, '?', :s); end
def lmin_(i); seq(nil, i, :comma, '?', :list_min, :comma, '?', :s); end
def lhou_(i); seq(nil, i, :comma, '?', :list_hou, :comma, '?', :s); end
def ldom_(i); seq(nil, i, :comma, '?', :list_dom, :comma, '?', :s); end
def lmon_(i); seq(nil, i, :comma, '?', :list_mon, :comma, '?', :s); end
def ldow(i); seq(nil, i, :comma, '?', :list_dow, :comma, '?'); end

def _tz_name(i)
rex(nil, i, / +[A-Z][a-zA-Z0-9+\-]+(\/[A-Z][a-zA-Z0-9+\-_]+){0,2}/)
Expand Down
6 changes: 6 additions & 0 deletions spec/cron_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1158,6 +1158,12 @@ class Fugit::Cron::TimeCursor
#
# some cronds are different, see https://crontab.guru/#7_0/1_*_*_*

[ '9,,19 * * * *', '9,19 * * * *' ],
[ ',8 * * * *', '8 * * * *' ],
[ ',,10,,20, * * * *', '10,20 * * * *' ],
[ '10,,20 * 1,,11,,21, * *', '10,20 * 1,11,21 * *' ],
[ ',,10,,22, * * * * Asia/Omsk', '10,22 * * * * Asia/Omsk' ],

].each { |c, e|

it "parses #{c}" do
Expand Down

0 comments on commit 052cfde

Please sign in to comment.