Hi all Im trying to track conflicts in Event Dates. So Im basically checking if event dates overlap
This is the code my boss helped me with however its showing records as overlapping when there is no conflict. Any ideas?
def perform (user_id)
user=User.find(user_id)
events=user.calendar.events
events.each do |e|
overlaps=events.where("(strftime(‘%s’,start) - strftime(‘%s’,?)) * (strftime(‘%s’,?) - strftime(‘%s’,end)) >= 0 ", e.start, e.end)
#exclude event id
if overlaps.any? where.not(“id = e.id”) #something like this
puts “FOUND AN OVERLAP”
end
end
#When using POSTGRES
#events.each do |e|
#e.start
#overlaps=events.where(“(start, end) OVERLAPS (?,?)”, e.start, e.end)
end