-
Notifications
You must be signed in to change notification settings - Fork 54
Open
Description
There's a bug in next_in_recurrence method of Event::Weekly:
private def next_in_recurrence
return @date if !initialized? && @options[:on].include?(@date.wday)
if (next_day = @options[:on].find {|day| day > @date.wday })
to_add = next_day - @date.wday
else
to_add = (7 - @date.wday) # Move to next week
to_add += (@options[:interval] - 1) * 7 # Add extra intervals
to_add += @options[:on].first # Go to first required day
end
new_date = @date.to_date + to_add
@options[:handler].call(new_date.day, new_date.month, new_date.year)
endIf @options[:on] is set to Sunday it gets converted to 0 which breaks the check in the if conditional. This in turn causes the code to skip to the else branch and miss one day.
The fix is to map Sunday to be 7 instead of 0, therefore making sure it's compared correctly and no day is skipped:
next_day = @options[:on].map { |day| day == 0 ? 7 : day }.find {|day| day > @date.wday }
I can prep a PR if this gem is still maintained but I saw after last time there was still no release (#40)
Metadata
Metadata
Assignees
Labels
No labels