<commit_before>class Timeslot < ActiveRecord::Base
  belongs_to :tutor, class_name: 'User'
  belongs_to :student, class_name: 'User'

  validates_presence_of :start, :tutor_id
  validates :tutor_id, uniqueness: {
    scope: :start,
    message: 'you are already available at this time'
  }
  validate :tutor_and_student_unique
  validates :student_id, uniqueness: {
      scope: :start,
      message: 'you are already scheduled for another session at this time'
    }, unless: 'student_id.nil?'

  def end
    start + 30.minutes
  end

  def open?
    student.nil?
  end

  def new_york_ordinal_time
    start.in_time_zone("Eastern Time (US & Canada)").to_date.to_formatted_s(:long_ordinal)
  end

  def day_and_time
    start.in_time_zone("Eastern Time (US & Canada)").strftime("%A at %I:%M%p")
  end

  def send_tutor_scheduling_email
    TimeslotMailer.tutor_scheduled(self).deliver_now unless self.tutor.email.nil?
  end

  def send_student_scheduling_email
    TimeslotMailer.student_scheduled(self).deliver_now unless self.student.email.nil?
  end

  def send_tutor_cancel_email(student)
    TimeslotMailer.tutor_cancel(self, student).deliver_now unless self.tutor.email.nil?
  end

  def send_student_cancel_email(student)
    TimeslotMailer.student_cancel(self, student).deliver_now unless student.email.nil?
  end

  private

    def tutor_and_student_unique
      errors.add(:student_id, "you can't tutor yourself :/") if tutor_id == student_id
    end

end<commit_msg>Add Timeslot validation requiring start in future<commit_after>class Timeslot < ActiveRecord::Base
  belongs_to :tutor, class_name: 'User'
  belongs_to :student, class_name: 'User'

  validates_presence_of :start, :tutor_id
  validate :start_must_be_future
  validates :tutor_id, uniqueness: {
    scope: :start,
    message: 'you are already available at this time'
  }
  validate :tutor_and_student_unique
  validates :student_id, uniqueness: {
      scope: :start,
      message: 'you are already scheduled for another session at this time'
    }, unless: 'student_id.nil?'

  def end
    start + 30.minutes
  end

  def open?
    student.nil?
  end

  def new_york_ordinal_time
    start.in_time_zone("Eastern Time (US & Canada)").to_date.to_formatted_s(:long_ordinal)
  end

  def day_and_time
    start.in_time_zone("Eastern Time (US & Canada)").strftime("%A at %I:%M%p")
  end

  def send_tutor_scheduling_email
    TimeslotMailer.tutor_scheduled(self).deliver_now unless self.tutor.email.nil?
  end

  def send_student_scheduling_email
    TimeslotMailer.student_scheduled(self).deliver_now unless self.student.email.nil?
  end

  def send_tutor_cancel_email(student)
    TimeslotMailer.tutor_cancel(self, student).deliver_now unless self.tutor.email.nil?
  end

  def send_student_cancel_email(student)
    TimeslotMailer.student_cancel(self, student).deliver_now unless student.email.nil?
  end

  private

    def start_must_be_future
      if start.nil? || start <= Time.zone.now
        errors.add(:start, "must be in the future")
      end
    end

    def tutor_and_student_unique
      errors.add(:student_id, "you can't tutor yourself :/") if tutor_id == student_id
    end

end
{'fraction_non_alphanumeric': 0.08881889763779527, 'fraction_numerical': 0.0012598425196850393, 'mean_word_length': 4.13915857605178, 'pattern_counts': {'":': 0, '<': 6, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1320163', 'n_tokens_mistral': 1130, 'n_tokens_neox': 1066, 'n_words': 243}