Skip to content

Commit

Permalink
Fix bug with weekday option when shift is enabled
Browse files Browse the repository at this point in the history
  • Loading branch information
shime committed Nov 22, 2023
1 parent 211746b commit 1354774
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/recurrence/event/monthly.rb
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ class Monthly < Base # :nodoc: all
end

private def shift_to(date)
@options[:on] = date.day
@options[:on] = date.day unless @options[:weekday].present?
end

private def valid_ordinal?(ordinal)
Expand Down
9 changes: 9 additions & 0 deletions test/recurrence/date_shift_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -70,4 +70,13 @@ class DateShiftTest < Minitest::Test

assert_equal Date.new(2012, 2, 29), r.next
end

test "correctly recurrs for weekdays" do
r = recurrence(every: :month, starts: "2011-01-31", on: "first",
weekday: "monday", shift: true)

assert_equal Date.new(2011, 2, 7), r.events[0]
assert_equal Date.new(2011, 3, 7), r.events[1]
assert_equal Date.new(2011, 4, 4), r.events[2]
end
end

0 comments on commit 1354774

Please sign in to comment.