# File app/models/timeslot.rb, line 199
  def no_overlapping_timeslots
    # Ugly, ugly, SQL query follows... Still, it's the clearest way I
    # could find to check for overlapping timeslots
    sql_cond = "room_id = ? AND
        (start_time-COALESCE(tolerance_pre, ?)::interval BETWEEN 
             ?::timestamp - ?::interval AND ?::timestamp + ?::interval OR 
         start_time+COALESCE(tolerance_post, ?)::interval BETWEEN 
             ?::timestamp - ?::interval AND ?::timestamp + ?::interval)"

    pre = effective_tolerance_pre
    d_pre = self.class.default_tolerance_pre
    post = effective_tolerance_post
    d_post = self.class.default_tolerance_pre

    others = self.class.find(:all, 
        :conditions => [sql_cond, room_id,
                        d_pre, start_time, pre, start_time, post,
                        d_post, start_time, pre, start_time, post]
                             ).select {|ts| ts.id != self.id}
    return true if others.empty?

    errors.add(:start_time, _('Timeslot is overlapping on room %s with %s') %
               [self.room.name, others.map {|ts| ts.id}.join(', ')])
  end