I just noticed something which is causing me a tad bit of trouble.
I am creating an object. This object goes into the database with this:
created_at: "2015-11-12 08:37:35.413663"
I didn't realize it stores beyond .413
You can confirm this is saved and not simply for our viewing pleasure by doing the following: object.created_at.nsec #=> 413663000
When my front-end receives my JSON, the created_ at attribute becomes: "2015-11-12T08:37:35.413Z", which I would expect. The problem here is that we lose valuable information because now we don't have the 633 microseconds.
Indeed, if you do "2015-11-12T08:37:35.413Z".to_time.nsec #=> 413000000.
What this means is when you do the following, you're going to get no item:
Object.where(created_at: object.created_at.as_json).first #=> nil
How does one mitigate this? How does one account for the microseconds, or rather, query for created_at, with only millisecond precision hope.
Ultimately, I decided on changing the datetime columns in my DB.
I basically applied the following wherever relevant in a migration:
change_column table, column, :datetime, limit: 3
That successfully makes sure that my :datetime columns all only go to the milliseconds.
I think it is a good change because when the sole purpose of my back-end is to render a JSON API, then I think through and through it should be cohesive. JSON API standards are ISO 8601. As such, I'd like my DB to adhere to that.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With