From 135477469a4d7623529731d01d4b6f025f944023 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hrvoje=20=C5=A0imi=C4=87?= Date: Wed, 22 Nov 2023 16:53:23 +0100 Subject: [PATCH] Fix bug with weekday option when shift is enabled --- lib/recurrence/event/monthly.rb | 2 +- test/recurrence/date_shift_test.rb | 9 +++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/lib/recurrence/event/monthly.rb b/lib/recurrence/event/monthly.rb index 63695f5..4c4f1bf 100644 --- a/lib/recurrence/event/monthly.rb +++ b/lib/recurrence/event/monthly.rb @@ -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) diff --git a/test/recurrence/date_shift_test.rb b/test/recurrence/date_shift_test.rb index b77a3ec..128c5ab 100644 --- a/test/recurrence/date_shift_test.rb +++ b/test/recurrence/date_shift_test.rb @@ -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