Add users
This commit is contained in:
parent
956f2625fd
commit
162aa095d3
15 changed files with 489 additions and 99 deletions
|
@ -1,10 +1,41 @@
|
|||
defmodule NullaWeb.UserHTML do
|
||||
@moduledoc """
|
||||
This module contains pages rendered by UserController.
|
||||
|
||||
See the `user_html` directory for all templates available.
|
||||
"""
|
||||
use NullaWeb, :html
|
||||
|
||||
embed_templates "user_html/*"
|
||||
|
||||
@doc """
|
||||
Renders a user form.
|
||||
"""
|
||||
attr :changeset, Ecto.Changeset, required: true
|
||||
attr :action, :string, required: true
|
||||
|
||||
def user_form(assigns)
|
||||
|
||||
def format_birthdate(date) do
|
||||
formatted = Date.to_string(date) |> String.replace("-", "/")
|
||||
age = Timex.diff(Timex.today(), date, :years)
|
||||
"#{formatted} (#{age} years old)"
|
||||
end
|
||||
|
||||
def format_registration_date(date) do
|
||||
now = Timex.now()
|
||||
formatted = Date.to_string(date) |> String.replace("-", "/")
|
||||
|
||||
diff = Timex.diff(now, date, :days)
|
||||
|
||||
relative =
|
||||
cond do
|
||||
diff == 0 -> "today"
|
||||
diff == 1 -> "1 day ago"
|
||||
diff < 30 -> "#{diff} days ago"
|
||||
diff < 365 ->
|
||||
months = Timex.diff(now, date, :months)
|
||||
if months == 1, do: "1 month ago", else: "#{months} months ago"
|
||||
true ->
|
||||
years = Timex.diff(now, date, :years)
|
||||
if years == 1, do: "1 year ago", else: "#{years} years ago"
|
||||
end
|
||||
|
||||
"#{formatted} (#{relative})"
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue