I am trying to parse incoming csv files containing one field with date-time string using fluentd(written in ruby) but it throws error for provided custom time format.
To check whether I am using correct format, I wrote sample ruby code(not a ruby programmer so used online ruby IDE) and found that the format works well when I try to write using it but ruby throws error when I try to read using this format :
[ code ]
require 'time'
time = Time.new
puts "writing time : " + time.strftime("%d-%b-%y %I.%M.%S.%9N %p")
newtime = Time.strptime("29-Sep-16 07.45.45.331680519 PM", "%d-%b-%y %I.%M.%S.%9N %p")
puts "reading time : " + newtime
[ output ]
sh-4.3$ ruby main.rb
writing time : 29-Sep-16 05.47.36.206929933 PM
/usr/share/ruby/time.rb:427:in `strptime': invalid strptime format - `%d-%b-%y %I.%M.%S.%9N %p' (ArgumentError)
from main.rb:10:in `<main>'
I checked many posts where people found issues with strptime but could not understand how to resolve above. Pls suggest.
Looks like the problem was with %9N - it is not supported. I changed %9N to %N and the parsing was successful.
http://ruby-doc.org/stdlib-1.9.3/libdoc/date/rdoc/DateTime.html specifies formats like %3N, %9N etc for parsing milliseconds, nanoseconds.. but it doesn't seem to work.
Thanks to tadman for suspecting this specifier.