2020-01-26 20:36:50 +00:00
|
|
|
defmodule Mobilizon.Web.EmailView do
|
|
|
|
use Mobilizon.Web, :view
|
2019-09-30 16:18:04 +00:00
|
|
|
|
2021-03-23 14:18:03 +00:00
|
|
|
alias Cldr.DateTime.Relative
|
2020-01-26 20:36:50 +00:00
|
|
|
import Mobilizon.Web.Gettext
|
2019-10-01 11:08:09 +00:00
|
|
|
|
2020-02-18 07:57:00 +00:00
|
|
|
def datetime_to_string(%DateTime{} = datetime, locale \\ "en", format \\ :medium) do
|
2019-09-30 16:18:04 +00:00
|
|
|
with {:ok, string} <-
|
2020-02-18 07:57:00 +00:00
|
|
|
Mobilizon.Cldr.DateTime.to_string(datetime, format: format, locale: locale) do
|
|
|
|
string
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def datetime_to_time_string(%DateTime{} = datetime, locale \\ "en", format \\ :hm) do
|
|
|
|
with {:ok, string} <-
|
|
|
|
Mobilizon.Cldr.DateTime.to_string(datetime, format: format, locale: locale) do
|
2019-09-30 16:18:04 +00:00
|
|
|
string
|
|
|
|
end
|
|
|
|
end
|
2020-11-16 17:28:52 +00:00
|
|
|
|
|
|
|
@spec datetime_tz_convert(DateTime.t(), String.t()) :: DateTime.t()
|
|
|
|
def datetime_tz_convert(%DateTime{} = datetime, timezone) do
|
|
|
|
case DateTime.shift_zone(datetime, timezone) do
|
|
|
|
{:ok, datetime_with_user_tz} ->
|
|
|
|
datetime_with_user_tz
|
|
|
|
|
|
|
|
_ ->
|
|
|
|
datetime
|
|
|
|
end
|
|
|
|
end
|
2021-03-23 14:18:03 +00:00
|
|
|
|
|
|
|
@spec datetime_relative(DateTime.t(), String.t()) :: String.t()
|
|
|
|
def datetime_relative(%DateTime{} = datetime, locale \\ "en") do
|
|
|
|
Relative.to_string!(datetime, Mobilizon.Cldr,
|
|
|
|
relative_to: DateTime.utc_now(),
|
|
|
|
locale: locale
|
|
|
|
)
|
|
|
|
end
|
2018-10-11 15:37:39 +00:00
|
|
|
end
|