Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle starting time when at option is supplied with every x.minutes #695

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
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
3 changes: 2 additions & 1 deletion lib/whenever/cron.rb
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,8 @@ def parse_time
raise ArgumentError, "Time must be in minutes or higher"
when Whenever.seconds(1, :minute)...Whenever.seconds(1, :hour)
minute_frequency = @time / 60
timing[0] = comma_separated_timing(minute_frequency, 59, @at || 0)
starting_minute = @at.is_a?(Time) ? @at.min : @at
timing[0] = comma_separated_timing(minute_frequency, 59, starting_minute || 0)
when Whenever.seconds(1, :hour)...Whenever.seconds(1, :day)
hour_frequency = (@time / 60 / 60).round
timing[0] = @at.is_a?(Time) ? @at.min : @at
Expand Down
1 change: 1 addition & 0 deletions test/unit/cron_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ class CronTest < Whenever::TestCase
assert_equal '* * * * *', parse_time(Whenever.seconds(1, :minute))
assert_equal '0,5,10,15,20,25,30,35,40,45,50,55 * * * *', parse_time(Whenever.seconds(5, :minutes))
assert_equal '7,14,21,28,35,42,49,56 * * * *', parse_time(Whenever.seconds(7, :minutes))
assert_equal '5,12,19,26,33,40,47,54 * * * *', parse_time(Whenever.seconds(7, :minutes), 'Test Task', '9:05 am')
assert_equal '0,30 * * * *', parse_time(Whenever.seconds(30, :minutes))
assert_equal '32 * * * *', parse_time(Whenever.seconds(32, :minutes))
assert '60 * * * *' != parse_time(Whenever.seconds(60, :minutes)) # 60 minutes bumps up into the hour range
Expand Down