2012-08-29 13:21:56 +00:00
|
|
|
module ApplicationHelper
|
2013-04-22 21:28:10 +00:00
|
|
|
|
2014-01-21 14:51:03 +00:00
|
|
|
|
2020-10-14 02:05:08 +00:00
|
|
|
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
|
|
|
|
|
|
2020-10-17 17:30:42 +00:00
|
|
|
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
|
2020-10-14 02:05:08 +00:00
|
|
|
Date.strptime(date, "%m#{delimiter}%d#{delimiter}%Y")
|
|
|
|
|
else
|
|
|
|
|
Date.strptime(date, "%Y#{delimiter}%m#{delimiter}%d")
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
2012-08-29 13:21:56 +00:00
|
|
|
end
|