Reputation: 57
Basically I'm just trying to sift through a csv with unix timestamps, and not sure what is going wrong as I looked at other solutions on this site.
Error
csv_parsing.rb:13
:in `at': can't convert String into an exact number (TypeError)
My unix_timestamps_array variable is an array of strings composed of unix timestamps for example "1237178109" but dont feel like attaching the csv. I can confirm that before ln 7 I am getting the array of unix timestamps in the terminal.
require 'csv'
require 'date'
csv = CSV.read('sample_data.csv', headers: true)
unix_time_str_array = csv['created_at']
unix_time_int_array = unix_time_str_array.map {|e| e.to_i }
converted_time = unix_time_int_array.each {|timestamp| Time.at(timestamp)}
p converted_time
Upvotes: 0
Views: 1351
Reputation: 52357
You need to pass a Numeric instance, not string:
Time.at("1237178109")
#=> TypeError: can't convert String into an exact number
But
Time.at(1237178109)
#=> 2009-03-16 06:35:09 +0200
Upvotes: 2