1 defmodule Pleroma.Web.ActivityPub.ObjectValidators.Types.DateTime do
3 The AP standard defines the date fields in AP as xsd:DateTime. Elixir's
4 DateTime can't parse this, but it can parse the related iso8601. This
5 module punches the date until it looks like iso8601 and normalizes to
8 DateTimes without a timezone offset are treated as UTC.
10 Reference: https://www.w3.org/TR/activitystreams-vocabulary/#dfn-published
16 def cast(datetime) when is_binary(datetime) do
17 with {:ok, datetime, _} <- DateTime.from_iso8601(datetime) do
18 {:ok, DateTime.to_iso8601(datetime)}
20 {:error, :missing_offset} -> cast("#{datetime}Z")
25 def cast(_), do: :error