Skip to content

Commit

Permalink
Merge pull request #88 from delbetu/parse-nat-support-last
Browse files Browse the repository at this point in the history
Parse Nat support for 1st and last of the month
  • Loading branch information
jmettraux committed Sep 26, 2023
2 parents 051a7f2 + 8bec4b4 commit d3d7984
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
4 changes: 3 additions & 1 deletion lib/fugit/nat.rb
Original file line number Diff line number Diff line change
Expand Up @@ -691,8 +691,10 @@ def parse_cron(hm, opts)
a << tz.data0 if tz
a.shift if a.first == [ '0' ]

letters_first = ->(x) { x.is_a?(Numeric) ? x : 0 }

s = a
.collect { |e| e.uniq.sort.collect(&:to_s).join(',') }
.collect { |e| e.uniq.sort_by(&letters_first).collect(&:to_s).join(',') }
.join(' ')

c = Fugit::Cron.parse(s)
Expand Down
2 changes: 2 additions & 0 deletions spec/nat_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@
'every month on the 1st and 2nd at 12:00 pm' => '0 12 1,2 * *',
'every month on the 1st and the 2nd at 12:00 pm' => '0 12 1,2 * *',
'every month on the 1st and the second at 12:00 pm' => '0 12 1,2 * *',
'every month on the 1st and last at 12:00 pm' => '0 12 L,1 * *',
'every month on the 1st and the last at 12:00 pm' => '0 12 L,1 * *',
#
# gh-57, 12pm --> noon

Expand Down

0 comments on commit d3d7984

Please sign in to comment.