There must be a better way of converting dates than this ugly mess ?

def convert_date format, s

case format

when “yymmddhhmmss”

year = s[0,2].to_i + 2000

month= s[2,2].to_i

day = s[4,2].to_i

hour = s[6,2].to_i

minute=s[8,2].to_i

second=s[10,2].to_i

Time.local(year,month,day,hour,minute,second)

when “yyyymmddhhmm”

year = s[0,4].to_i

month= s[4,2].to_i

day = s[6,2].to_i

hour = s[8,2].to_i

minute=s[10,2].to_i

Time.local(year,month,day,hour,minute)

when “ddmmyyhhmm”

day = s[0,2].to_i

month= s[2,2].to_i

year = s[4,2].to_i + 2000

hour = s[6,2].to_i

minute=s[8,2].to_i

Time.local(year,month,day,hour,minute)

when “yyyymmdd”

year = s[0,4].to_i

month= s[4,2].to_i

day = s[6,2].to_i

Time.local(year,month,day)

end

end

Christer