Skip to content

Commit

Permalink
re-add timeframe-omit
Browse files Browse the repository at this point in the history
  • Loading branch information
joelhawksley committed Oct 6, 2024
1 parent 175618c commit 557e013
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 1 deletion.
4 changes: 4 additions & 0 deletions app/models/calendar_event.rb
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,10 @@ def private?
@summary == "timeframe-private" || @description == "timeframe-private"
end

def omit?
@description == "timeframe-omit"
end

def start_i
@starts_at.to_i
end
Expand Down
2 changes: 1 addition & 1 deletion app/models/calendar_feed.rb
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ def events_for(starts_at, ends_at, events = [], private_mode = false)
else
(event.start_i...event.end_i).overlaps?(starts_at.to_i...ends_at.to_i)
end
end
end.select { !_1.omit? }

# Merge duplicate events, merging the letter with a custom rule if so
filtered_events = filtered_events.group_by { _1.id }
Expand Down
19 changes: 19 additions & 0 deletions test/models/calendar_feed_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -248,4 +248,23 @@ def test_filtering_private_events
assert(CalendarFeed.new.events_for(start_time_utc, end_time_utc, calendar_events, true)[:periodic].length == 0)
end
end

def test_excludes_omit
calendar_events = [
CalendarEvent.new(
id: "foo",
starts_at: DateTime.new(2023, 8, 27, 15, 20, 0, "-0600"),
ends_at: DateTime.new(2023, 8, 27, 20, 20, 0, "-0600"),
summary: "Hide me!",
description: "timeframe-omit"
)
]

travel_to DateTime.new(2023, 8, 27, 17, 20, 0, "-0600") do
start_time_utc = DateTime.new(2023, 8, 27, 0, 20, 0, "-0600").utc.to_time
end_time_utc = DateTime.new(2023, 8, 28, 0, 0, 0, "-0600").utc.to_time

assert(CalendarFeed.new.events_for(start_time_utc, end_time_utc, calendar_events)[:periodic].length == 0)
end
end
end

0 comments on commit 557e013

Please sign in to comment.