1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2020 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
5 defmodule Pleroma.EctoType.ActivityPub.ObjectValidators.DateTime do
7 The AP standard defines the date fields in AP as xsd:DateTime. Elixir's
8 DateTime can't parse this, but it can parse the related iso8601. This
9 module punches the date until it looks like iso8601 and normalizes to
12 DateTimes without a timezone offset are treated as UTC.
14 Reference: https://www.w3.org/TR/activitystreams-vocabulary/#dfn-published
20 def cast(datetime) when is_binary(datetime) do
21 with {:ok, datetime, _} <- DateTime.from_iso8601(datetime) do
22 {:ok, DateTime.to_iso8601(datetime)}
24 {:error, :missing_offset} -> cast("#{datetime}Z")
29 def cast(_), do: :error