Skip to content

Instantly share code, notes, and snippets.

@shamil614
Last active December 20, 2015 07:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save shamil614/6090840 to your computer and use it in GitHub Desktop.
Save shamil614/6090840 to your computer and use it in GitHub Desktop.
# find any jobs that chronologically overlap an array of job_assignments
# ex: find any jobs that overlap an interpreter's existing jobs via the job_assignments
def self.overlapping(job_assignments)
jobs_table = Job.arel_table
query = Job.scoped
job_assignments.each do |ja|
query = query.where((jobs_table[:start_datetime].in(ja.scheduled_start..ja.estimated_end)).
or(jobs_table[:end_datetime].in(ja.scheduled_start..ja.estimated_end)))
end
query
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment