module ApplicationHelper


  def parse_user_type(user_type, options)
    if user_type == 'Student'
      options[:student] = true
    elsif user_type == 'Student Instructor'
      options[:teacher] = true
    elsif user_type == 'Platform Instructor'
      options[:platform_instructor] = true
    else
      raise JamRuby::JamPermissionError, "Unknown user type #{user_type}"
    end
  end

  def parse_date(date)
    delimiter = '/'
    bits = date.split(delimiter)

    if bits.length != 3
      delimiter = '-'
      bits = date.split(delimiter)
    end

    if bits.length != 3
      raise JamRuby::JamPermissionError, "date #{date} has no '-' or '/'"
    end

    if bits[2].length == 4 || (bits[0].length != 4 && bits[2].to_i > 12)  # excel likes to do 1/1/20. So if last
      if bits[2].length == 2
        # prepend year

        date = [bits[0], bits[1], '20' + bits[2]].join(delimiter)
      end
      Date.strptime(date, "%m#{delimiter}%d#{delimiter}%Y")
    else
      Date.strptime(date, "%Y#{delimiter}%m#{delimiter}%d")
    end

  end


end
