mirror of
https://github.com/philomena-dev/philomena.git
synced 2024-12-03 16:17:59 +01:00
23 lines
578 B
Elixir
23 lines
578 B
Elixir
defmodule Philomena.Schema.Time do
|
|
alias Philomena.RelativeDate
|
|
import Ecto.Changeset
|
|
|
|
def assign_time(changeset, field, target_field) do
|
|
changeset
|
|
|> get_field(field)
|
|
|> RelativeDate.parse()
|
|
|> case do
|
|
{:ok, time} ->
|
|
put_change(changeset, target_field, time)
|
|
|
|
_err ->
|
|
add_error(changeset, field, "is not a valid relative or absolute date and time")
|
|
end
|
|
end
|
|
|
|
def propagate_time(changeset, field, target_field) do
|
|
time = get_field(changeset, field)
|
|
|
|
put_change(changeset, target_field, to_string(time))
|
|
end
|
|
end
|