<commit_before>Spree::Order.class_eval do
  require 'date'

  attr_accessible :delivery_date

  validate :delivery_date, :presence => true, :allow_nil => false
  validate :delivery_date_specific_validation, :if => :validate_delivery_date? 

  def delivery_date_specific_validation
    # Ensure that a delivery date is set. We don't want to run these validations until it is
    if !delivery_date.blank?
      puts '00---------------------------'
      puts 'running validation'
      puts '------------------------------'
      # Check if delivery date is sunday or monday, which are not allowed
      if [0, 1, 7].include?(delivery_date.wday)
        errors.add(:delivery_date, "cannot be a Sunday or Monday.")
      end

      cutoff = Time.now.change(:hour => 17, :min => 00).in_time_zone("Eastern Time (US & Canada)")
      puts cutoff
      if cutoff.past?
        # It is past 5:00. Order must be > Date.tomorrow
        if !(delivery_date > Date.tomorrow)
          errors.add(:delivery_date, ": It is too late for delivery tomorrow. Please specify a date after tomorrow.")
        end
      else
        if !(delivery_date > Date.today)
          errors.add(:delivery_date, ": It is too late for delivery today. Please specify a date tomorrow or later.")
        end
      end
    end<commit_msg>Only validate if not in cart or address step<commit_after>Spree::Order.class_eval do
  require 'date'

  attr_accessible :delivery_date

  validate :delivery_date, :presence => true, :allow_nil => false
  validate :delivery_date_specific_validation, :if => :validate_delivery_date? 

  def delivery_date_specific_validation
    # Ensure that a delivery date is set. We don't want to run these validations until it is
    if !delivery_date.blank?
      puts '00---------------------------'
      puts 'running validation'
      puts state
      puts '------------------------------'
      # Check if delivery date is sunday or monday, which are not allowed
      if [0, 1, 7].include?(delivery_date.wday)
        errors.add(:delivery_date, "cannot be a Sunday or Monday.")
      end

      cutoff = Time.now.change(:hour => 17, :min => 00).in_time_zone("Eastern Time (US & Canada)")
      puts cutoff
      if cutoff.past?
        # It is past 5:00. Order must be > Date.tomorrow
        if !(delivery_date > Date.tomorrow)
          errors.add(:delivery_date, ": It is too late for delivery tomorrow. Please specify a date after tomorrow.")
        end
      else
        if !(delivery_date > Date.today)
          errors.add(:delivery_date, ": It is too late for delivery today. Please specify a date tomorrow or later.")
        end
      end
    end
{'fraction_non_alphanumeric': 0.1280120481927711, 'fraction_numerical': 0.009036144578313253, 'mean_word_length': 2.410783055198973, 'pattern_counts': {'":': 4, '<': 3, '<?xml version=': 0, '>': 19, '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': '1657739', 'n_tokens_mistral': 781, 'n_tokens_neox': 751, 'n_words': 265}