<commit_before>class Day < ActiveRecord::Base
  attr_accessible :date, :total_time, :reason, :approved, :month_id, :denied
  validates :date, :reason, presence: true
  validate :valid_total, :valid_date
  belongs_to :month
  has_many :activities, :dependent => :destroy
  accepts_nested_attributes_for :activities, :allow_destroy => true

  # Returns the total number of activity-days pending approval
  def self.num_pending
    Day.count(:conditions => {:approved => false, :denied => false})
  end

  def user ; self.month.user ; end

  def valid_total
    if total_time < 60
      errors.add(:total, "can't be less than 60 mins")
    elsif total_time > 1440
      errors.add(:total, "can't be more than 24 hours")
    end
  end

  def valid_date
    unless approved
      today = Date.today
      start_date = today.beginning_of_month
      start_date =  today.ago(1.month).beginning_of_month if today.strftime("%d").to_i < 6
      end_date = today.prev_day
      check_date_in_range(start_date, end_date)
    end
  end

  def check_date_in_range(start_date, end_date)
    unless ((start_date.to_date)..(end_date.to_date)) === (date.to_date)
      errors.add(:date, "#{date.strftime("%m/%d/%Y")} is not within allowed range")
    end
  end

  def approve_day
    approved = true
    month = self.month
    month.num_of_days += 1
    month.save!
  end

end<commit_msg>all tests passing<commit_after>class Day < ActiveRecord::Base
  attr_accessible :date, :total_time, :reason, :approved, :month_id, :denied
  validates :date, :reason, presence: true
  validate :valid_total, :valid_date
  belongs_to :month
  has_many :activities, :dependent => :destroy
  accepts_nested_attributes_for :activities, :allow_destroy => true

  # Returns the total number of activity-days pending approval
  def self.num_pending
    Day.count(:conditions => {:approved => false, :denied => false})
  end

  def user ; self.month.user ; end

  def valid_total
    if total_time < 60
      errors.add(:total, "can't be less than 60 mins")
    elsif total_time > 1440
      errors.add(:total, "can't be more than 24 hours")
    end
  end

  def valid_date
    unless approved
      today = Date.today
      start_date = today.beginning_of_month
      start_date =  today.ago(1.month).beginning_of_month if today.strftime("%d").to_i < 6
      end_date = today.prev_day
      check_date_in_range(start_date, end_date)
    end
  end

  def check_date_in_range(start_date, end_date)
    unless ((start_date.to_date)..(end_date.to_date)) === (date.to_date)
      errors.add(:date, "#{date.strftime("%m/%d/%Y")} is not within allowed range")
    end
  end

  def approve_day
    self.approved = true
    self.save!
    month = self.month
    month.num_of_days += 1
    month.save!
  end

end
{'fraction_non_alphanumeric': 0.10745296671490594, 'fraction_numerical': 0.009406657018813314, 'mean_word_length': 3.4886363636363638, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 15, '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': '608451', 'n_tokens_mistral': 968, 'n_tokens_neox': 912, 'n_words': 236}