rm Timex.diff/3 (#4695)

This commit is contained in:
ruslandoga 2024-11-04 16:18:04 +07:00 committed by GitHub
parent 13ad279820
commit 40f28ed151
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
12 changed files with 14 additions and 14 deletions

View File

@ -82,7 +82,7 @@ defmodule Plausible.Auth.GracePeriod do
def active?(user_or_team)
def active?(%{grace_period: %__MODULE__{end_date: %Date{} = end_date}}) do
Timex.diff(end_date, Date.utc_today(), :days) >= 0
Date.diff(end_date, Date.utc_today()) >= 0
end
def active?(%{grace_period: %__MODULE__{manual_lock: true}}) do

View File

@ -106,7 +106,7 @@ defmodule Plausible.Auth.UserAdmin do
"ended"
%{end_date: %Date{} = end_date} ->
days_left = Timex.diff(end_date, DateTime.utc_now(), :days)
days_left = Date.diff(end_date, Date.utc_today())
"#{days_left} days left"
end
end

View File

@ -81,7 +81,7 @@ defmodule Plausible.Plugins.API.Token do
diff =
if token.last_used_at do
now = NaiveDateTime.utc_now()
Timex.diff(now, token.last_used_at, :minutes)
NaiveDateTime.diff(now, token.last_used_at, :minute)
end
cond do

View File

@ -63,7 +63,7 @@ defmodule Plausible.Plugins.API.Tokens do
now = NaiveDateTime.truncate(now, :second)
last_used = token.last_used_at
if is_nil(last_used) or Timex.diff(now, last_used, :minutes) > 5 do
if is_nil(last_used) or NaiveDateTime.diff(now, last_used, :minute) > 5 do
token
|> Ecto.Changeset.change(%{last_used_at: now})
|> Repo.update()

View File

@ -62,7 +62,7 @@ defmodule Plausible.Session.CacheStore do
nil
session ->
if Timex.diff(event.timestamp, session.timestamp, :minutes) <= 30 do
if NaiveDateTime.diff(event.timestamp, session.timestamp, :minute) <= 30 do
session
end
end
@ -93,7 +93,7 @@ defmodule Plausible.Session.CacheStore do
exit_page_hostname:
if(event.name == "pageview", do: event.hostname, else: session.exit_page_hostname),
is_bounce: false,
duration: Timex.diff(event.timestamp, session.start, :second) |> abs,
duration: NaiveDateTime.diff(event.timestamp, session.start) |> abs,
pageviews:
if(event.name == "pageview", do: session.pageviews + 1, else: session.pageviews),
events: session.events + 1

View File

@ -45,7 +45,7 @@ defmodule Plausible.Stats.Interval do
Timex.diff(last, first, :months) > 0 ->
"month"
Timex.diff(last, first, :days) > 0 ->
DateTime.diff(last, first, :day) > 0 ->
"day"
true ->

View File

@ -85,8 +85,8 @@ defmodule Plausible.Stats.QueryOptimizer do
defp resolve_time_dimension(first, last) do
cond do
Timex.diff(last, first, :hours) <= 48 -> "time:hour"
Timex.diff(last, first, :days) <= 40 -> "time:day"
DateTime.diff(last, first, :hour) <= 48 -> "time:hour"
DateTime.diff(last, first, :day) <= 40 -> "time:day"
Timex.diff(last, first, :weeks) <= 52 -> "time:week"
true -> "time:month"
end

View File

@ -26,7 +26,7 @@ defmodule Plausible.Users do
@spec trial_days_left(Auth.User.t()) :: integer()
def trial_days_left(user) do
Timex.diff(user.trial_expiry_date, Date.utc_today(), :days)
Date.diff(user.trial_expiry_date, Date.utc_today())
end
@spec update_accept_traffic_until(Auth.User.t()) :: Auth.User.t()

View File

@ -274,7 +274,7 @@ defmodule PlausibleWeb.Components.Billing.PlanBox do
trial_active_or_ended_recently? =
not invited_user? &&
Timex.diff(Date.utc_today(), current_user.trial_expiry_date, :days) <= 10
Date.diff(Date.utc_today(), current_user.trial_expiry_date) <= 10
limit_checking_opts =
cond do

View File

@ -107,7 +107,7 @@ defmodule PlausibleWeb.LayoutView do
end
def grace_period_end(%{grace_period: %{end_date: %Date{} = date}}) do
case Timex.diff(date, Date.utc_today(), :days) do
case Date.diff(date, Date.utc_today()) do
0 -> "today"
1 -> "tomorrow"
n -> "within #{n} days"

View File

@ -44,7 +44,7 @@ defmodule Plausible.Workers.SendSiteSetupEmails do
for site <- Repo.all(q) do
owner = Plausible.Users.with_subscription(site.owner)
setup_completed = Plausible.Sites.has_stats?(site)
hours_passed = Timex.diff(DateTime.utc_now(), site.inserted_at, :hours)
hours_passed = NaiveDateTime.diff(DateTime.utc_now(), site.inserted_at, :hour)
if !setup_completed && hours_passed > 47 do
send_setup_help_email(owner, site)

View File

@ -20,7 +20,7 @@ defmodule Plausible.Workers.SendTrialNotifications do
)
for user <- users do
case Timex.diff(user.trial_expiry_date, Date.utc_today(), :days) do
case Date.diff(user.trial_expiry_date, Date.utc_today()) do
7 ->
if Plausible.Auth.has_active_sites?(user, [:owner]) do
send_one_week_reminder(user)