Skip to content

Commit bf22e26

Browse files
committed
add multi day event count
1 parent 6251bea commit bf22e26

File tree

4 files changed

+18
-2
lines changed

4 files changed

+18
-2
lines changed

app/models/calendar_event.rb

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,11 +101,16 @@ def time
101101
end
102102
end
103103

104-
def summary
104+
def summary(as_of = nil)
105105
if (1900..2100).cover?(@description.to_s.to_i)
106106
counter = Date.today.year - @description.to_s.to_i
107107

108108
"#{@summary} (#{counter})"
109+
elsif multi_day? && as_of
110+
numerator = (as_of.to_date - @starts_at.to_date).to_i + 1
111+
denominator = (@ends_at.to_date - @starts_at.to_date).to_i
112+
113+
"#{@summary} (#{numerator}/#{denominator})"
109114
else
110115
@summary
111116
end.gsub(/\p{Emoji_Presentation}/, "").strip

app/models/display_content.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,7 @@ def call(
131131

132132
{
133133
day_name: day_name,
134+
date: date.to_date,
134135
events: events
135136
}
136137
end.compact

app/views/displays/_timeline.html.slim

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
i.fa-fw.fa-solid class="fa-#{event.icon}"
1313
td
1414
div
15-
= event.summary
15+
= event.summary(event_day[:date])
1616
div style="font-size: .5rem;" = event.location
1717
div style="width: 30rem;"
1818
table style="width: 100%"

test/models/calendar_event_test.rb

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,4 +193,14 @@ def test_strips_emoji
193193

194194
assert_equal("foo", event.summary)
195195
end
196+
197+
def test_daily_summary_count
198+
event = CalendarEvent.new(
199+
starts_at: DateTime.new(2023, 1, 23),
200+
ends_at: DateTime.new(2023, 1, 25),
201+
summary: "foo"
202+
)
203+
204+
assert_equal(event.summary(DateTime.new(2023, 1, 24)), "foo (2/2)")
205+
end
196206
end

0 commit comments

Comments
 (0)