Conduit v0.4.0 Conduit.Plug.CreatedAt

Assigns a created_at date to the message.

A format can be specified. The default is "{ISO:Extended:Z}". The format can be anything that Timex.format/1 accepts. See here.

:unix_epoch may also be passed, which will set the timestamp to seconds since the UNIX epoch.

plug Conduit.Plug.CreatedAt
plug Conduit.Plug.CreatedAt, format: "{YYYY}-{M}-{D}"
plug Conduit.Plug.CreatedAt, format: :unix_epoch

Summary

Functions

Assigns a ISO8601 timestamp to the message

Callback implementation for Conduit.Plug.init/1

Functions

call(message, opts)
call(Conduit.Message.t, binary | atom) :: Conduit.Message.t

Assigns a ISO8601 timestamp to the message.

Examples

iex> message = Conduit.Plug.CreatedAt.call(%Conduit.Message{}, "{ISO:Extended:Z}")
iex> # e.g. "2016-11-16T03:00:24.575904Z"
iex> {:ok, %DateTime{}} = Timex.parse(message.created_at, "{ISO:Extended:Z}")
iex> message = Conduit.Plug.CreatedAt.call(%Conduit.Message{}, :unix_epoch)
iex> # e.g. 1479265596
iex> is_integer(message.created_at)
true
init(opts)

Callback implementation for Conduit.Plug.init/1.