devinus / poison

An incredibly fast, pure Elixir JSON library

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Configurable timestamp output format

simpers opened this issue · comments

We would need to be able to change the default output format for this timestamp. I have a fork of version 3.1 where I added a setting for this. I have not converted it to version 4 yet as I am not sure Phoenix supports it.

Is it possible to change the following line to something more like below?

Encoder.BitString.encode(@for.to_iso8601(value), options)

case Application.get_env(:poison, :datetime_formatter) do
  nil ->
    Poison.Encoder.BitString.encode(@for.to_iso8601(value), options)
  formatter ->
    Poison.Encoder.BitString.encode(formatter.format(value), options)
end

This would allow the consumer to override the datetime output format while still defaulting to the previous behaviour.

I have not found any other system-wide solution for making sure that all the datetimes we output have the same format. If you'd to make an exception, I guess you just have to format it to a string before you encode it, but this is for all timestamps present when encoding.