I am working through Chris Pine’s Ruby book, and I am slightly confused why my code doesn’t quite work.
I have a file called birthdays.txt which has around 10 lines of text which resembles:
Andy Rogers, 1987, 02, 03
etc.
My code as follows:
hash = {}
File.open('birthdays.txt', "r+").each_line do |line|
name, date = line.chomp.split( /, */, 2 )
hash[name] = date
end
puts 'whose birthday would you like to know?'
name = gets.chomp
puts hash[name]
puts Time.local(hash[name])
My question is, why does the last line of code, Time.local(hash[name]) produce this output?:
1987-01-01 00:00:00 +0000
instead of:
1987-02-03 00:00:00 +0000
1 Answer