Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove Timex.today #4357

Merged
merged 2 commits into from
Jul 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/mix/tasks/download_country_database.ex
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ defmodule Mix.Tasks.DownloadCountryDatabase do
def run(_) do
Application.ensure_all_started(:httpoison)
Application.ensure_all_started(:timex)
this_month = Timex.today()
this_month = Date.utc_today()
last_month = Date.shift(this_month, month: -1)
this_month = this_month |> Date.to_iso8601() |> binary_part(0, 7)
last_month = last_month |> Date.to_iso8601() |> binary_part(0, 7)
Expand Down
4 changes: 2 additions & 2 deletions lib/plausible/auth/grace_period.ex
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ defmodule Plausible.Auth.GracePeriod do
"""
def start_changeset(%User{} = user) do
grace_period = %__MODULE__{
end_date: Date.shift(Timex.today(), day: 7),
end_date: Date.shift(Date.utc_today(), day: 7),
is_over: false,
manual_lock: false
}
Expand Down Expand Up @@ -82,7 +82,7 @@ defmodule Plausible.Auth.GracePeriod do
def active?(user)

def active?(%User{grace_period: %__MODULE__{end_date: %Date{} = end_date}}) do
Timex.diff(end_date, Timex.today(), :days) >= 0
Timex.diff(end_date, Date.utc_today(), :days) >= 0
end

def active?(%User{grace_period: %__MODULE__{manual_lock: true}}) do
Expand Down
6 changes: 3 additions & 3 deletions lib/plausible/auth/user.ex
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ defmodule Plausible.Auth.User do
end

def end_trial(user) do
change(user, trial_expiry_date: Timex.today() |> Date.shift(day: -1))
change(user, trial_expiry_date: Date.utc_today() |> Date.shift(day: -1))
end

def password_strength(changeset) do
Expand Down Expand Up @@ -253,9 +253,9 @@ defmodule Plausible.Auth.User do

defp trial_expiry() do
on_ee do
Timex.today() |> Date.shift(day: 30)
Date.utc_today() |> Date.shift(day: 30)
else
Timex.today() |> Date.shift(year: 100)
Date.utc_today() |> Date.shift(year: 100)
end
end

Expand Down
4 changes: 2 additions & 2 deletions lib/plausible/billing/paddle_api.ex
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,8 @@ defmodule Plausible.Billing.PaddleApi do
vendor_auth_code: config[:vendor_auth_code],
subscription_id: subscription.paddle_subscription_id,
is_paid: 1,
from: Date.shift(Timex.today(), year: -5) |> Timex.format!("{YYYY}-{0M}-{0D}"),
to: Date.shift(Timex.today(), day: 1) |> Timex.format!("{YYYY}-{0M}-{0D}")
from: Date.shift(Date.utc_today(), year: -5) |> Timex.format!("{YYYY}-{0M}-{0D}"),
to: Date.shift(Date.utc_today(), day: 1) |> Timex.format!("{YYYY}-{0M}-{0D}")
}

with {:ok, %{body: body}} <- HTTPClient.post(invoices_url(), @headers, params),
Expand Down
2 changes: 1 addition & 1 deletion lib/plausible/billing/qouta/usage.ex
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ defmodule Plausible.Billing.Quota.Usage do
end

@spec usage_cycle(User.t(), :last_30_days | cycle(), list() | nil, Date.t()) :: usage_cycle()
def usage_cycle(user, cycle, owned_site_ids \\ nil, today \\ Timex.today())
def usage_cycle(user, cycle, owned_site_ids \\ nil, today \\ Date.utc_today())

def usage_cycle(user, cycle, nil, today) do
usage_cycle(user, cycle, Plausible.Sites.owned_site_ids(user), today)
Expand Down
2 changes: 1 addition & 1 deletion lib/plausible/billing/subscriptions.ex
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ defmodule Plausible.Billing.Subscriptions do

def expired?(%Subscription{next_bill_date: next_bill_date} = subscription) do
deleted? = Subscription.Status.deleted?(subscription)
expired? = Timex.compare(next_bill_date, Timex.today()) < 0
expired? = Timex.compare(next_bill_date, Date.utc_today()) < 0

deleted? && expired?
end
Expand Down
2 changes: 1 addition & 1 deletion lib/plausible/google/ga4/http.ex
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ defmodule Plausible.Google.GA4.HTTP do
%{
property: "#{property}",
dateRanges: [
%{startDate: @earliest_valid_date, endDate: Date.to_iso8601(Timex.today())}
%{startDate: @earliest_valid_date, endDate: Date.to_iso8601(Date.utc_today())}
],
dimensions: [%{name: "date"}],
metrics: [%{name: "screenPageViews"}],
Expand Down
3 changes: 2 additions & 1 deletion lib/plausible/imported.ex
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,8 @@ defmodule Plausible.Imported do

@spec get_cutoff_date(Site.t()) :: Date.t()
def get_cutoff_date(site) do
Plausible.Sites.native_stats_start_date(site) || Timex.today(site.timezone)
Plausible.Sites.native_stats_start_date(site) ||
DateTime.to_date(DateTime.now!(site.timezone))
end

defp find_free_ranges(start_date, end_date, occupied_ranges) do
Expand Down
2 changes: 1 addition & 1 deletion lib/plausible/users.ex
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,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, Timex.today(), :days)
Timex.diff(user.trial_expiry_date, Date.utc_today(), :days)
end

@spec update_accept_traffic_until(Auth.User.t()) :: Auth.User.t()
Expand Down
2 changes: 1 addition & 1 deletion lib/plausible_web/components/billing/plan_box.ex
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@ defmodule PlausibleWeb.Components.Billing.PlanBox do
invited_user? = is_nil(user.trial_expiry_date)

trial_active_or_ended_recently? =
not invited_user? && Timex.diff(Timex.today(), user.trial_expiry_date, :days) <= 10
not invited_user? && Timex.diff(Date.utc_today(), user.trial_expiry_date, :days) <= 10

limit_checking_opts =
cond do
Expand Down
2 changes: 1 addition & 1 deletion lib/plausible_web/views/layout_view.ex
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ defmodule PlausibleWeb.LayoutView do
end

def grace_period_end(%{grace_period: %{end_date: %Date{} = date}}) do
case Timex.diff(date, Timex.today(), :days) do
case Timex.diff(date, Date.utc_today(), :days) do
0 -> "today"
1 -> "tomorrow"
n -> "within #{n} days"
Expand Down
2 changes: 1 addition & 1 deletion lib/workers/check_usage.ex
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ defmodule Plausible.Workers.CheckUsage do
end

@impl Oban.Worker
def perform(_job, usage_mod \\ Quota.Usage, today \\ Timex.today()) do
def perform(_job, usage_mod \\ Quota.Usage, today \\ Date.utc_today()) do
yesterday = today |> Date.shift(day: -1)

active_subscribers =
Expand Down
2 changes: 1 addition & 1 deletion lib/workers/send_trial_notifications.ex
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ defmodule Plausible.Workers.SendTrialNotifications do
)

for user <- users do
case Timex.diff(user.trial_expiry_date, Timex.today(), :days) do
case Timex.diff(user.trial_expiry_date, Date.utc_today(), :days) do
7 ->
if Plausible.Auth.has_active_sites?(user, [:owner]) do
send_one_week_reminder(user)
Expand Down
Loading