[fix] Fix time displayed in happening_now.haml; Make event_schedule#happening_now? more efficient

This commit is contained in:
Jimmy 2021-03-19 17:13:34 +08:00 committed by CactusPuppy
parent 2628952142
commit 85fe894876
No known key found for this signature in database
GPG key ID: 4B33B0A3E15E2C82
2 changed files with 6 additions and 7 deletions

View file

@ -55,9 +55,10 @@ class EventSchedule < ApplicationRecord
# True within `threshold` before and after the event. # True within `threshold` before and after the event.
# #
def happening_now?(threshold = 30.minutes) def happening_now?(threshold = 30.minutes)
return false if end_time < Time.now
event_time_range = start_time..end_time event_time_range = start_time..end_time
now_range = (Time.now - threshold)..(Time.now + threshold) now_range = (Time.now - threshold)..(Time.now + threshold)
event_time_range.overlaps?(now_range) && (end_time > Time.now) event_time_range.overlaps?(now_range)
end end
def self.withdrawn_or_canceled_event_schedules(schedule_ids) def self.withdrawn_or_canceled_event_schedules(schedule_ids)

View file

@ -9,12 +9,10 @@
.col-md-12 .col-md-12
%h2 %h2
#{pluralize(@events_schedules.count, 'Event')} Occurring Within The Next 30 minutes. #{pluralize(@events_schedules.count, 'Event')} Occurring Within The Next 30 minutes.
%br %h3
%small This page was loaded at
This page was loaded at = inyourtz(Time.now) do
= inyourtz(Time.now) do #{Time.now.strftime('%a %b %d at %I:%M %P (%z)').to_s}
= Time.now.strftime('%a %b %d at %I:%M %P (%z)')
\.
.row .row
/ TODO: Clean this up, merge with all events page. / TODO: Clean this up, merge with all events page.