Add a Happening Now View

This commit is contained in:
Michael Ball 2020-07-30 22:31:45 -07:00
parent 0d4733b130
commit 70bde86dd6
8 changed files with 80 additions and 9 deletions

View file

@ -31,7 +31,7 @@ class Ability
event.state == 'confirmed'
end
can [:show, :events, :app], Schedule do |schedule|
can [:show, :events, :happening_now, :app], Schedule do |schedule|
schedule.program.schedule_public
end

View file

@ -274,6 +274,14 @@ class Event < ApplicationRecord
event_schedules.find_by(schedule_id: selected_schedule_id).try(:start_time)
end
##
# Returns the start time at which this event is scheduled
#
def happening_now?
event_schedules.find_by(schedule_id: selected_schedule_id).try(:happening_now?)
end
##
# Returns true or false, if the event is already over or not
#

View file

@ -27,15 +27,21 @@ class EventSchedule < ApplicationRecord
delegate :guid, to: :room, prefix: true
delegate :timezone, to: :event
def timezone
event.conference.timezone
end
##
# True within 1 hour before and after the event.
# True within `threshold` before and after the event.
#
def happening_now?(threshold=30.minutes)
pre_start_time = (start_time - threshold).in_time_zone(timezone)
end_time_with_threshold = (end_time + threshold).in_time_zone(timezone)
(pre_start_time..end_time_with_threshold).cover?(Time.now.in_time_zone(timezone))
in_tz_start = start_time.in_time_zone(timezone)
in_tz_end = start_time.in_time_zone(timezone)
in_tz_start -= in_tz_start.utc_offset
in_tz_end -= in_tz_end.utc_offset
begin_range = Time.now - threshold
end_range = Time.now + threshold + 1.minute # The range is exclusive.
(begin_range..end_range).cover?(in_tz_start) || (begin_range..end_range).cover?(in_tz_end)
end
def self.withdrawn_or_canceled_event_schedules(schedule_ids)