Task observer implementation I need help cleaning up this piece of code.

if is_complete == true
  #If there are time stamps get between time stamps
  if start_date &amp;&amp; end_date
    tasks = Task.find(:all, :include =&gt; [:task_observer, :job, :contact], :conditions =&gt; ["contact_id = ? and completed_date IS NOT NULL and DATE(completed_date) between ? and ?", contact_id, start_date, end_date])
  else
    tasks = Task.find(:all, :include =&gt; [:task_observer, :job, :contact], :conditions =&gt; ["contact_id = ? and completed_date IS NOT NULL", contact_id])
  end
else
  #If there are time stamps get between time stamps
  if start_date &amp;&amp; end_date
    tasks = Task.find(:all, :include =&gt; [:task_observer, :job, :contact], :conditions =&gt; ["contact_id = ? and completed_date IS NULL and DATE(completed_date) between ? and ?", contact_id, start_date, end_date])
  else
    tasks = Task.find(:all, :include =&gt; [:task_observer, :job, :contact], :conditions =&gt; ["contact_id = ? and completed_date IS NULL", contact_id])
  end
end
you can replace if is_complete == true with if is_complete
the only thing that changes is :conditions, tasks = ... should not be inside the if/else
the 3rd case is invalid: completed_date can't be NULL and within a certain range at the same time
use one conditional for the NOT in completed_date IS (NOT) NULL and one for the and DATE ..., and concatenate the sql string then. Then the nested if/else is gone.
the extra query arguments start_date and end_date depend only on start_date &amp;&amp; end_date, so the distinctions should not be in the is_completed conditional.