From 84ed7988a8ad5bf883d15251955f03c3793470dd Mon Sep 17 00:00:00 2001 From: ruslandoga Date: Thu, 9 May 2024 13:59:23 +0700 Subject: [PATCH] Drop `local_start_date/1` (#4088) --- lib/plausible/sites.ex | 29 ----------------------------- lib/plausible/stats/query.ex | 2 +- test/plausible/stats/query_test.exs | 2 +- 3 files changed, 2 insertions(+), 31 deletions(-) diff --git a/lib/plausible/sites.ex b/lib/plausible/sites.ex index 12d4235adfa1..eb792946ff63 100644 --- a/lib/plausible/sites.ex +++ b/lib/plausible/sites.ex @@ -196,35 +196,6 @@ defmodule Plausible.Sites do |> Plausible.Repo.update!() end - @doc """ - Returns the date of the first recorded stat in the timezone configured by the user. - This function does 2 transformations: - UTC %NaiveDateTime{} -> Local %DateTime{} -> Local %Date - - ## Examples - - iex> Plausible.Site.local_start_date(%Plausible.Site{stats_start_date: nil}) - nil - - iex> utc_start = ~N[2022-09-28 00:00:00] - iex> tz = "Europe/Helsinki" - iex> site = %Plausible.Site{stats_start_date: utc_start, timezone: tz} - iex> Plausible.Site.local_start_date(site) - ~D[2022-09-28] - - iex> utc_start = ~N[2022-09-28 00:00:00] - iex> tz = "America/Los_Angeles" - iex> site = %Plausible.Site{stats_start_date: utc_start, timezone: tz} - iex> Plausible.Site.local_start_date(site) - ~D[2022-09-27] - """ - @spec local_start_date(Site.t()) :: Date.t() | nil - def local_start_date(site) do - if stats_start_date = stats_start_date(site) do - Plausible.Timezones.to_date_in_timezone(stats_start_date, site.timezone) - end - end - @spec stats_start_date(Site.t()) :: Date.t() | nil @doc """ Returns the date of the first event of the given site, or `nil` if the site diff --git a/lib/plausible/stats/query.ex b/lib/plausible/stats/query.ex index bf4adaeace48..00bf937ed88d 100644 --- a/lib/plausible/stats/query.ex +++ b/lib/plausible/stats/query.ex @@ -150,7 +150,7 @@ defmodule Plausible.Stats.Query do defp put_period(query, site, %{"period" => "all"}) do now = today(site.timezone) - start_date = Plausible.Sites.local_start_date(site) || now + start_date = Plausible.Sites.stats_start_date(site) || now struct!(query, period: "all", diff --git a/test/plausible/stats/query_test.exs b/test/plausible/stats/query_test.exs index c56e0f978a9d..3e38c748e3fc 100644 --- a/test/plausible/stats/query_test.exs +++ b/test/plausible/stats/query_test.exs @@ -105,7 +105,7 @@ defmodule Plausible.Stats.QueryTest do site = Map.put(site, :timezone, "America/Cancun") q = Query.from(site, %{"period" => "all"}) - assert q.date_range.first == ~D[2019-12-31] + assert q.date_range.first == ~D[2020-01-01] assert q.date_range.last == Timex.today("America/Cancun") end