Update
This commit is contained in:
parent
3a57d74357
commit
df548a4943
12 changed files with 137 additions and 179 deletions
|
@ -18,33 +18,37 @@ defmodule NullaWeb.ActorHTML do
|
|||
def format_registration_date(date) do
|
||||
now = Date.utc_today()
|
||||
formatted = Date.to_string(date) |> String.replace("-", "/")
|
||||
|
||||
|
||||
diff_days = Date.diff(now, date)
|
||||
|
||||
|
||||
cond do
|
||||
diff_days == 0 ->
|
||||
"#{formatted} (today)"
|
||||
|
||||
|
||||
diff_days == 1 ->
|
||||
"#{formatted} (1 day ago)"
|
||||
|
||||
|
||||
diff_days < 30 ->
|
||||
"#{formatted} (#{diff_days} days ago)"
|
||||
|
||||
|
||||
diff_days < 365 ->
|
||||
year_diff = now.year - date.year
|
||||
month_diff = now.month - date.month
|
||||
day_correction = if now.day < date.day, do: -1, else: 0
|
||||
months = year_diff * 12 + month_diff + day_correction
|
||||
|
||||
if months == 1 do
|
||||
"#{formatted} (1 month ago)"
|
||||
else
|
||||
"#{formatted} (#{months} months ago)"
|
||||
end
|
||||
|
||||
|
||||
true ->
|
||||
year_diff = now.year - date.year
|
||||
years = if {now.month, now.day} < {date.month, date.day}, do: year_diff - 1, else: year_diff
|
||||
|
||||
years =
|
||||
if {now.month, now.day} < {date.month, date.day}, do: year_diff - 1, else: year_diff
|
||||
|
||||
if years == 1 do
|
||||
"#{formatted} (1 year ago)"
|
||||
else
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue