From e548210f8dbd4ff231d0a28ccbd7cd85d9116735 Mon Sep 17 00:00:00 2001 From: omochiumaiumai Date: Thu, 23 Nov 2023 04:51:12 +0900 Subject: [PATCH 01/11] =?UTF-8?q?=E6=AC=A1=E3=81=AE=E7=AC=ACn=20X=E6=9B=9C?= =?UTF-8?q?=E6=97=A5=E3=81=AE=E6=97=A5=E4=BB=98=E3=82=92=E8=A8=88=E7=AE=97?= =?UTF-8?q?=E3=81=99=E3=82=8B=E5=87=A6=E7=90=86=E3=82=92=E3=83=A1=E3=82=BD?= =?UTF-8?q?=E3=83=83=E3=83=89=E3=81=AB=E5=88=87=E3=82=8A=E5=87=BA=E3=81=97?= =?UTF-8?q?=20/=20=E7=A5=9D=E6=97=A5=E3=82=B9=E3=82=AD=E3=83=83=E3=83=97?= =?UTF-8?q?=E3=81=AE=E5=87=A6=E7=90=86=E3=82=92=E8=BF=BD=E5=8A=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/models/regular_event.rb | 28 ++++++++++++++++++++-------- 1 file changed, 20 insertions(+), 8 deletions(-) diff --git a/app/models/regular_event.rb b/app/models/regular_event.rb index 9275a9dcb4e..4e3141259f9 100644 --- a/app/models/regular_event.rb +++ b/app/models/regular_event.rb @@ -110,19 +110,31 @@ def next_event_date end def possible_next_event_date(first_day, repeat_rule) - if repeat_rule.frequency.zero? - next_specific_day_of_the_week(repeat_rule) if Time.zone.today.mon == first_day.mon - else - # 次の第n X曜日の日付を計算する - date = (repeat_rule.frequency - 1) * DAYS_OF_THE_WEEK_COUNT + repeat_rule.day_of_the_week - first_day.wday + 1 - date += DAYS_OF_THE_WEEK_COUNT if repeat_rule.day_of_the_week < first_day.wday - Date.new(first_day.year, first_day.mon, date) + return next_specific_day_of_the_week(repeat_rule) if repeat_rule.frequency.zero? + + possible_date = next_month_specific_day_of_the_week(repeat_rule, first_day, DAYS_OF_THE_WEEK_COUNT) + + return possible_date if hold_national_holiday + + while possible_date.mon == first_day.mon && HolidayJp.holiday?(possible_date) + first_day = first_day.next_month + possible_date = next_month_specific_day_of_the_week(repeat_rule, first_day, DAYS_OF_THE_WEEK_COUNT) end + possible_date end def next_specific_day_of_the_week(repeat_rule) day_of_the_week_symbol = DateAndTime::Calculations::DAYS_INTO_WEEK.key(repeat_rule.day_of_the_week) - 0.days.ago.next_occurring(day_of_the_week_symbol).to_date + possible_date = 0.days.ago.next_occurring(day_of_the_week_symbol).to_date + possible_date = possible_date.next_occurring(day_of_the_week_symbol) while !hold_national_holiday && HolidayJp.holiday?(possible_date) + possible_date + end + + def next_month_specific_day_of_the_week(repeat_rule, first_day, days_of_the_week_count) + # 次の第n X曜日の日付を計算する + date = (repeat_rule.frequency - 1) * days_of_the_week_count + repeat_rule.day_of_the_week - first_day.wday + 1 + date += days_of_the_week_count if repeat_rule.day_of_the_week < first_day.wday + Date.new(first_day.year, first_day.mon, date) end def holding_tomorrow? From 5eccee2919bdf7585911be3dd39d85cf73d12f65 Mon Sep 17 00:00:00 2001 From: omochiumaiumai Date: Thu, 23 Nov 2023 05:10:36 +0900 Subject: [PATCH 02/11] =?UTF-8?q?=E7=A5=9D=E6=97=A5=E3=81=AB=E9=96=8B?= =?UTF-8?q?=E5=82=AC=E3=81=97=E3=81=AA=E3=81=84=E3=81=8B=E3=81=A4=E7=A5=9D?= =?UTF-8?q?=E6=97=A5=E3=81=AE=E5=A0=B4=E5=90=88=E3=80=81false=E3=82=92?= =?UTF-8?q?=E8=BF=94=E3=81=99=E3=82=88=E3=81=86=E3=81=AB=E5=A4=89=E6=9B=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/models/regular_event.rb | 2 ++ 1 file changed, 2 insertions(+) diff --git a/app/models/regular_event.rb b/app/models/regular_event.rb index 4e3141259f9..6e7ccc2d685 100644 --- a/app/models/regular_event.rb +++ b/app/models/regular_event.rb @@ -78,6 +78,8 @@ def organizers end def holding_today? + return false if !hold_national_holiday && HolidayJp.holiday?(Time.zone.today) + now = Time.current event_day = regular_event_repeat_rules.map do |repeat_rule| if repeat_rule.frequency.zero? From 25dd9b64eae38d762bcb8e1ee868614a45485bc6 Mon Sep 17 00:00:00 2001 From: omochiumaiumai Date: Thu, 23 Nov 2023 17:42:18 +0900 Subject: [PATCH 03/11] =?UTF-8?q?=E3=83=A1=E3=82=BD=E3=83=83=E3=83=89?= =?UTF-8?q?=E5=90=8D=E3=81=AE=E5=A4=89=E6=9B=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/models/regular_event.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/app/models/regular_event.rb b/app/models/regular_event.rb index 6e7ccc2d685..9fb109270f1 100644 --- a/app/models/regular_event.rb +++ b/app/models/regular_event.rb @@ -114,13 +114,13 @@ def next_event_date def possible_next_event_date(first_day, repeat_rule) return next_specific_day_of_the_week(repeat_rule) if repeat_rule.frequency.zero? - possible_date = next_month_specific_day_of_the_week(repeat_rule, first_day, DAYS_OF_THE_WEEK_COUNT) + possible_date = calculate_nth_weekday_date(repeat_rule, first_day, DAYS_OF_THE_WEEK_COUNT) return possible_date if hold_national_holiday while possible_date.mon == first_day.mon && HolidayJp.holiday?(possible_date) first_day = first_day.next_month - possible_date = next_month_specific_day_of_the_week(repeat_rule, first_day, DAYS_OF_THE_WEEK_COUNT) + possible_date = calculate_nth_weekday_date(repeat_rule, first_day, DAYS_OF_THE_WEEK_COUNT) end possible_date end @@ -132,7 +132,7 @@ def next_specific_day_of_the_week(repeat_rule) possible_date end - def next_month_specific_day_of_the_week(repeat_rule, first_day, days_of_the_week_count) + def calculate_nth_weekday_date(repeat_rule, first_day, days_of_the_week_count) # 次の第n X曜日の日付を計算する date = (repeat_rule.frequency - 1) * days_of_the_week_count + repeat_rule.day_of_the_week - first_day.wday + 1 date += days_of_the_week_count if repeat_rule.day_of_the_week < first_day.wday From 736ebac0a7434b64a31e5d68b3edc7193c5cdf9d Mon Sep 17 00:00:00 2001 From: omochiumaiumai Date: Thu, 23 Nov 2023 18:31:54 +0900 Subject: [PATCH 04/11] =?UTF-8?q?=E7=A5=9D=E6=97=A5=E9=9D=9E=E9=96=8B?= =?UTF-8?q?=E5=82=AC=E3=81=AE=E3=82=A4=E3=83=99=E3=83=B3=E3=83=88=E3=82=92?= =?UTF-8?q?=E3=82=B9=E3=82=AD=E3=83=83=E3=83=97=E3=81=99=E3=82=8B=E3=83=86?= =?UTF-8?q?=E3=82=B9=E3=83=88=E3=82=92=E8=BF=BD=E5=8A=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- test/models/regular_event_test.rb | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/test/models/regular_event_test.rb b/test/models/regular_event_test.rb index 377f31f9a08..06ccec327a5 100644 --- a/test/models/regular_event_test.rb +++ b/test/models/regular_event_test.rb @@ -48,6 +48,13 @@ class RegularEventTest < ActiveSupport::TestCase first_day = Time.zone.today assert_equal Date.new(2022, 6, 5), regular_event.possible_next_event_date(first_day, regular_event_repeat_rule) end + + holiday_not_held_event = regular_events(:regular_event33) + repeat_rule = regular_event_repeat_rules(:regular_event_repeat_rule36) # 第1週水曜日 + travel_to Time.zone.local(2020, 1, 1, 0, 0, 0) do + first_day = Time.zone.today + assert_equal Date.new(2020, 2, 5), holiday_not_held_event.possible_next_event_date(first_day, repeat_rule) + end end test '#next_specific_day_of_the_week' do @@ -56,6 +63,13 @@ class RegularEventTest < ActiveSupport::TestCase travel_to Time.zone.local(2022, 6, 1, 0, 0, 0) do assert_equal Date.new(2022, 6, 5), regular_event.next_specific_day_of_the_week(regular_event_repeat_rule) end + + holiday_not_held_event = regular_events(:regular_event33) + repeat_rule = regular_event_repeat_rules(:regular_event_repeat_rule35) # 毎週水曜日 + travel_to Time.zone.local(2020, 1, 1, 0, 0, 0) do + first_day = Time.zone.today + assert_equal Date.new(2020, 1, 8), holiday_not_held_event.possible_next_event_date(first_day, repeat_rule) + end end test '#holding_tomorrow?' do From 31d4c1b44ad5553851c5b870ac80d37eb7880f22 Mon Sep 17 00:00:00 2001 From: omochiumaiumai Date: Thu, 23 Nov 2023 19:07:16 +0900 Subject: [PATCH 05/11] =?UTF-8?q?calculate=5Fnth=5Fweekday=5Fdate=E3=83=A1?= =?UTF-8?q?=E3=82=BD=E3=83=83=E3=83=89=E3=81=AE=E3=83=86=E3=82=B9=E3=83=88?= =?UTF-8?q?=E3=82=92=E8=BF=BD=E5=8A=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- test/models/regular_event_test.rb | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/test/models/regular_event_test.rb b/test/models/regular_event_test.rb index 06ccec327a5..b2825275c00 100644 --- a/test/models/regular_event_test.rb +++ b/test/models/regular_event_test.rb @@ -72,6 +72,17 @@ class RegularEventTest < ActiveSupport::TestCase end end + test '#calculate_nth_weekday_date' do + regular_event = regular_events(:regular_event1) + repeat_rule = regular_event_repeat_rules(:regular_event_repeat_rule2) + days_of_the_week_count = 7 + + travel_to Time.zone.local(2020, 1, 1, 0, 0, 0) do + first_day = Time.zone.today + assert_equal Date.new(2020, 1, 6), regular_event.calculate_nth_weekday_date(repeat_rule, first_day, days_of_the_week_count) + end + end + test '#holding_tomorrow?' do regular_event = regular_events(:regular_event1) travel_to Time.zone.local(2023, 2, 25, 0, 0, 0) do From 8dd2b31034a04176a38ea7d4ad904e8066eea787 Mon Sep 17 00:00:00 2001 From: omochiumaiumai Date: Thu, 23 Nov 2023 19:10:46 +0900 Subject: [PATCH 06/11] =?UTF-8?q?fixture=E3=82=92=E8=BF=BD=E5=8A=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- test/fixtures/regular_event_repeat_rules.yml | 10 ++++++++++ test/fixtures/regular_events.yml | 11 +++++++++++ 2 files changed, 21 insertions(+) diff --git a/test/fixtures/regular_event_repeat_rules.yml b/test/fixtures/regular_event_repeat_rules.yml index 168f824cb48..c51608c585e 100644 --- a/test/fixtures/regular_event_repeat_rules.yml +++ b/test/fixtures/regular_event_repeat_rules.yml @@ -84,3 +84,13 @@ regular_event_repeat_rule34: frequency: 0 day_of_the_week: 1 regular_event: regular_event32 + +regular_event_repeat_rule35: + frequency: 0 + day_of_the_week: 3 + regular_event: regular_event33 + +regular_event_repeat_rule36: + frequency: 1 + day_of_the_week: 3 + regular_event: regular_event34 diff --git a/test/fixtures/regular_events.yml b/test/fixtures/regular_events.yml index 3c15d904384..f80937a9f77 100644 --- a/test/fixtures/regular_events.yml +++ b/test/fixtures/regular_events.yml @@ -155,3 +155,14 @@ regular_event32: user: komagata category: 0 published_at: "2023-08-01 00:00:00" + +regular_event33: + title: 次回開催日確認用、祝日非開催イベント(水曜日開催) + description: 次回開催日確認用、祝日非開催イベント(水曜日開催) + finished: false + hold_national_holiday: false + start_at: <%= Time.zone.local(2020, 1, 1, 21, 0, 0) %> + end_at: <%= Time.zone.local(2020, 1, 1, 22, 0, 0) %> + user: komagata + category: 0 + published_at: "2023-08-01 00:00:00" From c08fd6fa57c2ec652cafbeea0ba08e6fd94c9e16 Mon Sep 17 00:00:00 2001 From: omochiumaiumai Date: Wed, 29 Nov 2023 17:15:26 +0900 Subject: [PATCH 07/11] =?UTF-8?q?=E7=A5=9D=E6=97=A5=E9=9D=9E=E9=96=8B?= =?UTF-8?q?=E5=82=AC=E3=81=AE=E5=A0=B4=E5=90=88=E3=81=AE=E5=87=A6=E7=90=86?= =?UTF-8?q?=E3=82=92=E7=A7=BB=E5=8B=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/decorators/regular_event_decorator.rb | 2 +- app/models/regular_event.rb | 2 -- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/app/decorators/regular_event_decorator.rb b/app/decorators/regular_event_decorator.rb index 89ad5d5386f..42b51e9e1a5 100644 --- a/app/decorators/regular_event_decorator.rb +++ b/app/decorators/regular_event_decorator.rb @@ -13,7 +13,7 @@ def next_holding_date if finished '開催終了' elsif holding_today? - '本日開催' + !hold_national_holiday && HolidayJp.holiday?(Time.zone.today) ? "次回の開催日は #{l next_event_date} です" : '本日開催' else "次回の開催日は #{l next_event_date} です" end diff --git a/app/models/regular_event.rb b/app/models/regular_event.rb index 9fb109270f1..a28f88902ce 100644 --- a/app/models/regular_event.rb +++ b/app/models/regular_event.rb @@ -78,8 +78,6 @@ def organizers end def holding_today? - return false if !hold_national_holiday && HolidayJp.holiday?(Time.zone.today) - now = Time.current event_day = regular_event_repeat_rules.map do |repeat_rule| if repeat_rule.frequency.zero? From 4c7cc6a419f249b89ec0c76a8fe1150168813008 Mon Sep 17 00:00:00 2001 From: omochiumaiumai Date: Thu, 30 Nov 2023 02:21:58 +0900 Subject: [PATCH 08/11] =?UTF-8?q?=E8=BF=BD=E5=8A=A0=E3=81=97=E3=81=9Fregul?= =?UTF-8?q?ar=5Fevent33=E3=82=92=E5=89=8A=E9=99=A4=20/=20regular=5Fevent1?= =?UTF-8?q?=E3=81=AB=E5=A4=89=E6=9B=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- test/fixtures/regular_events.yml | 11 ----------- test/models/regular_event_test.rb | 4 ++-- 2 files changed, 2 insertions(+), 13 deletions(-) diff --git a/test/fixtures/regular_events.yml b/test/fixtures/regular_events.yml index f80937a9f77..3c15d904384 100644 --- a/test/fixtures/regular_events.yml +++ b/test/fixtures/regular_events.yml @@ -155,14 +155,3 @@ regular_event32: user: komagata category: 0 published_at: "2023-08-01 00:00:00" - -regular_event33: - title: 次回開催日確認用、祝日非開催イベント(水曜日開催) - description: 次回開催日確認用、祝日非開催イベント(水曜日開催) - finished: false - hold_national_holiday: false - start_at: <%= Time.zone.local(2020, 1, 1, 21, 0, 0) %> - end_at: <%= Time.zone.local(2020, 1, 1, 22, 0, 0) %> - user: komagata - category: 0 - published_at: "2023-08-01 00:00:00" diff --git a/test/models/regular_event_test.rb b/test/models/regular_event_test.rb index b2825275c00..4250eaabca5 100644 --- a/test/models/regular_event_test.rb +++ b/test/models/regular_event_test.rb @@ -49,7 +49,7 @@ class RegularEventTest < ActiveSupport::TestCase assert_equal Date.new(2022, 6, 5), regular_event.possible_next_event_date(first_day, regular_event_repeat_rule) end - holiday_not_held_event = regular_events(:regular_event33) + holiday_not_held_event = regular_events(:regular_event1) repeat_rule = regular_event_repeat_rules(:regular_event_repeat_rule36) # 第1週水曜日 travel_to Time.zone.local(2020, 1, 1, 0, 0, 0) do first_day = Time.zone.today @@ -64,7 +64,7 @@ class RegularEventTest < ActiveSupport::TestCase assert_equal Date.new(2022, 6, 5), regular_event.next_specific_day_of_the_week(regular_event_repeat_rule) end - holiday_not_held_event = regular_events(:regular_event33) + holiday_not_held_event = regular_events(:regular_event1) repeat_rule = regular_event_repeat_rules(:regular_event_repeat_rule35) # 毎週水曜日 travel_to Time.zone.local(2020, 1, 1, 0, 0, 0) do first_day = Time.zone.today From df28306038c0dcc9311104c3333785dcf639b162 Mon Sep 17 00:00:00 2001 From: omochiumaiumai Date: Mon, 11 Dec 2023 21:53:35 +0900 Subject: [PATCH 09/11] =?UTF-8?q?=E3=83=A1=E3=82=BD=E3=83=83=E3=83=89?= =?UTF-8?q?=E5=90=8D=E3=82=92=E5=A4=89=E6=9B=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/models/regular_event.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/app/models/regular_event.rb b/app/models/regular_event.rb index a28f88902ce..504601eb2ce 100644 --- a/app/models/regular_event.rb +++ b/app/models/regular_event.rb @@ -112,13 +112,13 @@ def next_event_date def possible_next_event_date(first_day, repeat_rule) return next_specific_day_of_the_week(repeat_rule) if repeat_rule.frequency.zero? - possible_date = calculate_nth_weekday_date(repeat_rule, first_day, DAYS_OF_THE_WEEK_COUNT) + possible_date = calculate_date_of_specific_nth_day_of_the_week(repeat_rule, first_day, DAYS_OF_THE_WEEK_COUNT) return possible_date if hold_national_holiday while possible_date.mon == first_day.mon && HolidayJp.holiday?(possible_date) first_day = first_day.next_month - possible_date = calculate_nth_weekday_date(repeat_rule, first_day, DAYS_OF_THE_WEEK_COUNT) + possible_date = calculate_date_of_specific_nth_day_of_the_week(repeat_rule, first_day, DAYS_OF_THE_WEEK_COUNT) end possible_date end @@ -130,7 +130,7 @@ def next_specific_day_of_the_week(repeat_rule) possible_date end - def calculate_nth_weekday_date(repeat_rule, first_day, days_of_the_week_count) + def calculate_date_of_specific_nth_day_of_the_week(repeat_rule, first_day, days_of_the_week_count) # 次の第n X曜日の日付を計算する date = (repeat_rule.frequency - 1) * days_of_the_week_count + repeat_rule.day_of_the_week - first_day.wday + 1 date += days_of_the_week_count if repeat_rule.day_of_the_week < first_day.wday From 7229060d450895ae0458e1ba3bb626d1a64a0859 Mon Sep 17 00:00:00 2001 From: omochiumaiumai Date: Mon, 11 Dec 2023 21:57:07 +0900 Subject: [PATCH 10/11] =?UTF-8?q?=E5=A4=89=E6=95=B0=E5=90=8D=E3=82=92?= =?UTF-8?q?=E5=A4=89=E6=9B=B4(`date`=E2=86=92`specific=5Fdate`)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/models/regular_event.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/app/models/regular_event.rb b/app/models/regular_event.rb index 504601eb2ce..046132d17aa 100644 --- a/app/models/regular_event.rb +++ b/app/models/regular_event.rb @@ -132,9 +132,9 @@ def next_specific_day_of_the_week(repeat_rule) def calculate_date_of_specific_nth_day_of_the_week(repeat_rule, first_day, days_of_the_week_count) # 次の第n X曜日の日付を計算する - date = (repeat_rule.frequency - 1) * days_of_the_week_count + repeat_rule.day_of_the_week - first_day.wday + 1 - date += days_of_the_week_count if repeat_rule.day_of_the_week < first_day.wday - Date.new(first_day.year, first_day.mon, date) + specific_date = (repeat_rule.frequency - 1) * days_of_the_week_count + repeat_rule.day_of_the_week - first_day.wday + 1 + specific_date += days_of_the_week_count if repeat_rule.day_of_the_week < first_day.wday + Date.new(first_day.year, first_day.mon, specific_date) end def holding_tomorrow? From 1148b7e90d033547caf72047669b1e4b5ef2d579 Mon Sep 17 00:00:00 2001 From: omochiumaiumai Date: Mon, 11 Dec 2023 22:15:45 +0900 Subject: [PATCH 11/11] =?UTF-8?q?=E3=83=86=E3=82=B9=E3=83=88=E3=82=92?= =?UTF-8?q?=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- test/models/regular_event_test.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/models/regular_event_test.rb b/test/models/regular_event_test.rb index 4250eaabca5..b80627c5768 100644 --- a/test/models/regular_event_test.rb +++ b/test/models/regular_event_test.rb @@ -72,14 +72,14 @@ class RegularEventTest < ActiveSupport::TestCase end end - test '#calculate_nth_weekday_date' do + test '#calculate_date_of_specific_nth_day_of_the_week' do regular_event = regular_events(:regular_event1) repeat_rule = regular_event_repeat_rules(:regular_event_repeat_rule2) days_of_the_week_count = 7 travel_to Time.zone.local(2020, 1, 1, 0, 0, 0) do first_day = Time.zone.today - assert_equal Date.new(2020, 1, 6), regular_event.calculate_nth_weekday_date(repeat_rule, first_day, days_of_the_week_count) + assert_equal Date.new(2020, 1, 6), regular_event.calculate_date_of_specific_nth_day_of_the_week(repeat_rule, first_day, days_of_the_week_count) end end