You can use regular comparators for date/times in Ruby (ie: >
, <
and ==
).
Something like the following should do what you are looking for:
if current_user.activities.where("(starts_at <= ? AND ends_at >= ?) OR (starts_at >= ? AND starts_at <= ?)", start_datetime, start_datetime, start_datetime, end_datetime).count
# There exist activities that fall between start_datetime and end_datetime
else
# There exist no such activities
end
(starts_at <= start_datetime AND ends_at >= start_datetime)
checks whether an event starts before and ends after start_datetime
.
(starts_at >= start_datetime AND starts_at <= end_datetime)
checks whether an event starts between start_datetime
and end_datetime
.