Skip to content

Commit

Permalink
Address gh-47, accept "* * * * Mon%2+2"
Browse files Browse the repository at this point in the history
let's not error on that
  • Loading branch information
jmettraux committed Apr 21, 2021
1 parent c8db960 commit af033bb
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 2 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.4.5 not yet released

* Accept "* * * Mon%2+2", gh-47


## fugit 1.4.4 released 2021-03-25

Expand Down
2 changes: 1 addition & 1 deletion CREDITS.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
* Danny Ben Shitrit https://github.com/DannyBen nat variants, gh-38
* Dominik Sander https://github.com/dsander #rough_frequency 0, gh-36
* Milovan Zogovic https://github.com/assembler Cron#match? vs TZ, gh-31
* Jessica Stokes https://github.com/ticky 0-24 issue with cron, gh-30
* Jessica Stokes https://github.com/ticky 0-24 issue with cron, gh-30 and gh-47
* Shai Coleman https://github.com/shaicoleman parse_nat enhancements, gh-24, gh-25, gh-28, and gh-37
* Jan Stevens https://github.com/JanStevens Fugit.parse('every 15 minutes') gh-22
* Fabio Pitino https://github.com/hspazio nil on February 30 gh-21
Expand Down
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,10 @@ c.match?('2019-01-08') # => false, since (rweek + 1) % 2 == 1
# ...
```

`sun%2` matches if Sunday and `current_date.rweek % 2 == 0`
`tue%3+2` matches if Tuesday and `current_date.rweek + 2 % 3 == 0`
`tue%x+y` matches if Tuesday and `current_date.rweek + y % x == 0`


## `Fugit::Duration`

Expand Down
2 changes: 1 addition & 1 deletion lib/fugit/cron.rb
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ def weekday_hash_match?(nt, hsh)

def weekday_modulo_match?(nt, mod)

nt.rweek % mod[0] == mod[1]
(nt.rweek + mod[1]) % mod[0] == 0
end

def weekday_match?(nt)
Expand Down
11 changes: 11 additions & 0 deletions spec/cron_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -551,6 +551,17 @@ class Fugit::Cron::TimeCursor
expect(nt.utc.to_s).to match(/ 16:00:00 /)
end
end

it 'does not break on "* * * * 1%2+2" (gh-47)' do

cron0 = Fugit.parse('0 8 * * 1%2+2')
cron1 = Fugit.parse('0 8 * * 1%2')

expect(cron0.next_time('2021-04-21 07:00:00').to_s
).to match(/^2021-05-03 08:00:00 /)
expect(cron0.next_time('2021-04-21 07:00:00').to_s
).to eq(cron1.next_time('2021-04-21 07:00:00').to_s)
end
end
end

Expand Down

0 comments on commit af033bb

Please sign in to comment.