I seem to have found a bug in Ruby, but I'm not sure so I'm posting it here.
I have a Rails app that fetches the latest objects after a given timestamp, which is the timestamp of the last object being shown on the page.
But for some reason it was always returning the last object duplicated. After a while, we decided to convert it to epoch, but it didn't work.
After trying to find where the issue might is, I've come up with the given code:
require 'date'
DateTime.strptime("1358895408.915", "%s").strftime("%s")
# => "1358895408"
Isn't this supposed to work? Am I missing something? How can I safely parse time and keep the milliseconds intact?
(Edited under suggestion following Andrew Marshall)
Use Time.at
. That will preserve milliseconds. It takes a numeric instead of a string.
Time.at(BigDecimal.new('1358895408.915'))
.strftime("%s.%L")
# => "1358895408.915"