Skip to content

Commit 864ca61

Browse files
committed
fix: /dojos/activity の開催日表示ロジックを改善
- note日付とイベント履歴日付のうち最新のものを優先表示 - 日本語形式の日付(YYYY年MM月DD日)をサポート - 既存のYYYY-MM-DD、YYYY/MM/DD形式に加えて日本語形式にも対応 これにより、手動でイベントを管理している道場でも最新の活動日が 正しく表示されるようになりました。
1 parent b934c41 commit 864ca61

File tree

2 files changed

+46
-10
lines changed

2 files changed

+46
-10
lines changed

app/controllers/dojos_controller.rb

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -115,8 +115,8 @@ def activity
115115
@latest_event_by_dojos = []
116116
Dojo.active.each do |dojo|
117117
link_in_note = dojo.note.match(URI.regexp)
118-
# YYYY-MM-DD または YYYY/MM/DD 形式の日付を抽出
119-
date_in_note = dojo.note.match(/(\d{4}-\d{1,2}-\d{1,2}|\d{4}\/\d{1,2}\/\d{1,2})/)
118+
# YYYY-MM-DDYYYY/MM/DD、または YYYY年MM月DD日 形式の日付を抽出
119+
date_in_note = dojo.note.match(/(\d{4}-\d{1,2}-\d{1,2}|\d{4}\/\d{1,2}\/\d{1,2}|\d{4}年\d{1,2}月\d{1,2}日)/)
120120

121121
latest_event = dojo.event_histories.newest.first
122122

@@ -132,7 +132,7 @@ def activity
132132
latest_event_url: latest_event.nil? ? nil : latest_event.event_url,
133133

134134
# note内の日付とリンク(fallback用)
135-
note_date: date_in_note.nil? ? nil : Time.zone.parse(date_in_note.to_s),
135+
note_date: parse_date_from_note(date_in_note),
136136
note_link: link_in_note.nil? ? nil : link_in_note.to_s
137137
}
138138
end
@@ -143,4 +143,21 @@ def activity
143143
[sort_date, dojo[:order]]
144144
end
145145
end
146+
147+
private
148+
149+
def parse_date_from_note(date_match)
150+
return nil if date_match.nil?
151+
152+
date_string = date_match.to_s
153+
154+
# 日本語形式の日付を標準形式に変換(例: 2025年8月24日 → 2025-08-24)
155+
if date_string.include?('年')
156+
date_string = date_string.gsub(/(\d{4})年(\d{1,2})月(\d{1,2})日/, '\1-\2-\3')
157+
end
158+
159+
Time.zone.parse(date_string)
160+
rescue ArgumentError
161+
nil
162+
end
146163
end

app/views/dojos/activity.html.erb

Lines changed: 26 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -79,14 +79,27 @@
7979
</td>
8080
<td>
8181
<small>
82-
<% if dojo[:latest_event_at] %>
83-
<!-- イベント履歴がある場合 -->
84-
<% expired = dojo[:latest_event_at] <= Time.current - @inactive_threshold && !dojo[:note].include?('Active') %>
85-
<span class="<%= 'expired' if expired %>">
86-
<%= link_to dojo[:latest_event_at].strftime("%Y-%m-%d"), dojo[:latest_event_url] %>
87-
</span>
82+
<% if dojo[:note_date] && dojo[:latest_event_at] %>
83+
<!-- 両方の日付がある場合:より新しい方を表示 -->
84+
<% if dojo[:note_date] > dojo[:latest_event_at] %>
85+
<!-- note日付の方が新しい -->
86+
<% expired = dojo[:note_date] <= Time.current - @inactive_threshold && !dojo[:note].include?('Active') %>
87+
<span class="<%= 'expired' if expired %>">
88+
<% if dojo[:note_link] %>
89+
<%= link_to dojo[:note_date].strftime("%Y-%m-%d"), dojo[:note_link] %>
90+
<% else %>
91+
<%= dojo[:note_date].strftime("%Y-%m-%d") %>
92+
<% end %>
93+
</span>
94+
<% else %>
95+
<!-- イベント履歴の方が新しいか同じ -->
96+
<% expired = dojo[:latest_event_at] <= Time.current - @inactive_threshold && !dojo[:note].include?('Active') %>
97+
<span class="<%= 'expired' if expired %>">
98+
<%= link_to dojo[:latest_event_at].strftime("%Y-%m-%d"), dojo[:latest_event_url] %>
99+
</span>
100+
<% end %>
88101
<% elsif dojo[:note_date] %>
89-
<!-- note内に日付がある場合 -->
102+
<!-- note日付のみ -->
90103
<% expired = dojo[:note_date] <= Time.current - @inactive_threshold && !dojo[:note].include?('Active') %>
91104
<span class="<%= 'expired' if expired %>">
92105
<% if dojo[:note_link] %>
@@ -95,6 +108,12 @@
95108
<%= dojo[:note_date].strftime("%Y-%m-%d") %>
96109
<% end %>
97110
</span>
111+
<% elsif dojo[:latest_event_at] %>
112+
<!-- イベント履歴のみ -->
113+
<% expired = dojo[:latest_event_at] <= Time.current - @inactive_threshold && !dojo[:note].include?('Active') %>
114+
<span class="<%= 'expired' if expired %>">
115+
<%= link_to dojo[:latest_event_at].strftime("%Y-%m-%d"), dojo[:latest_event_url] %>
116+
</span>
98117
<% else %>
99118
<!-- 開催日情報なし -->
100119
<span style="color: #999;">-</span>

0 commit comments

Comments
 (0)