Skip to content

Commit

Permalink
Drop local_start_date/1 (#4088)
Browse files Browse the repository at this point in the history
  • Loading branch information
ruslandoga committed May 9, 2024
1 parent 1114686 commit 84ed798
Show file tree
Hide file tree
Showing 3 changed files with 2 additions and 31 deletions.
29 changes: 0 additions & 29 deletions lib/plausible/sites.ex
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion lib/plausible/stats/query.ex
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion test/plausible/stats/query_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit 84ed798

Please sign in to comment.