stavro/arc_ecto

Microseconds in updated_at timestamp

Closed this issue · 4 comments

Today while I was running tests for my Phoenix application I noticed Arc.Ecto.Type casts filename into struct with updated_at timestamp which is not equal to the one it reads from database. For example, when I create a new record I get this struct:

%{file_name: "40683977_262339547749212_6971544430436155392_n.png", updated_at: ~N[2018-09-17 15:44:03.716235]}

but when I read it from the database I get the timestamp without microseconds.

%{file_name: "40683977_262339547749212_6971544430436155392_n.png", updated_at: ~N[2018-09-17 15:44:03]}

That's because the timestamp in the filename doesn't contain microseconds 40683977_262339547749212_6971544430436155392_n.png?63704418243.

This is the way dumping and loading works

iex(1)> :calendar.datetime_to_gregorian_seconds(NaiveDateTime.to_erl(~N[2018-09-17 15:44:03.716235]))
63704418243
iex(2)> NaiveDateTime.from_erl!(:calendar.gregorian_seconds_to_datetime(63704418243))
~N[2018-09-17 15:44:03]

I'm having the same problem. It's making all my tests fail.

  1) test technological_suggestion list_technological_suggestion/0 returns all technological_suggestion (FarmmixHomepage.TechnologicalSuggestionsTest)
     test/farmmix_homepage/documents/technological_suggestions_test.exs:10
     Assertion with == failed
     code:  assert TechnologicalSuggestions.list_technological_suggestion() == [technological_suggestion]
     left:  [%FarmmixHomepage.Documents.TechnologicalSuggestion{__meta__: #Ecto.Schema.Metadata<:loaded, "technological_suggestions">, id: 272, inserted_at: ~N[2018-09-27 14:28:34.863380], name: "name-0", updated_at: ~N[2018-09-27 14:28:34.863387], uuid: "e290a489-844a-3dc5-bd55-d3bed6b32888", file: %{file_name: "test.jpg", updated_at: ~N[2018-09-27 14:28:34]}}]
     right: [%FarmmixHomepage.Documents.TechnologicalSuggestion{__meta__: #Ecto.Schema.Metadata<:loaded, "technological_suggestions">, id: 272, inserted_at: ~N[2018-09-27 14:28:34.863380], name: "name-0", updated_at: ~N[2018-09-27 14:28:34.863387], uuid: "e290a489-844a-3dc5-bd55-d3bed6b32888", file: %{file_name: "test.jpg", updated_at: ~N[2018-09-27 14:28:34.858674]}}]

I have same problem, have anybody found temp. solution until @almirsarajcic fix is merged?

Well, yeah.
@dokicro, put this in mix.exs as a temporary solution:

defp deps do
  [
    {:arc_ecto, "~> 0.10", github: "almirsarajcic/arc_ecto", branch: "96-timestamp-microseconds"}
  ]
end

Thanks! 👍