I am trying to save a timestamp with millisecond precision in Rails, but the value gets up when I retrieve the record from the DB:
record.time_stamp = Time.utc(2017,1,1,1,1,1.35)
Check the time before saving:
record.time_stamp.strftime('%H:%M:%S.%L')
=> "01:01:01.350"
record.time_stamp.usec
=> 350000
record.time_stamp.to_f
=> 1483232461.35
Save and reload:
record.save!
record.reload
Check time after saving:
record.time_stamp.strftime('%H:%M:%S.%L')
=> "01:01:01.006"
record.time_stamp.usec
=> 6108
record.time_stamp.to_f
=> 1483232461.0061078
record.read_attribute_before_type_cast("time_stamp")
=> "2017-01-01 01:01:01.35"
Not sure what is going on here. The millisecond value stored in the database is correct, just like the original value before the type (see the last line), it just gets screwed when returning to Ruby Time.
NOTES:
( : Rails/ActiveRecord 4.2.6, ruby 2.3.0, Postgres 9.5.0, OSX)
UPDATE:
rails rails/ruby /postgres, , ! , , - , , , ... , .