mirror of
https://github.com/plausible/analytics.git
synced 2024-09-11 18:07:33 +03:00
Fix timezone display
This commit is contained in:
parent
03e6ffaba5
commit
9f2cdea503
@ -244,9 +244,11 @@ defmodule Plausible.Stats do
|
||||
defp base_query(site, query) do
|
||||
{:ok, first} = NaiveDateTime.new(query.date_range.first, ~T[00:00:00])
|
||||
first_datetime = Timex.to_datetime(first, site.timezone)
|
||||
|> Timex.Timezone.convert("UTC")
|
||||
|
||||
{:ok, last} = NaiveDateTime.new(query.date_range.last |> Timex.shift(days: 1), ~T[00:00:00])
|
||||
last_datetime = Timex.to_datetime(last, site.timezone)
|
||||
|> Timex.Timezone.convert("UTC")
|
||||
|
||||
from(e in Plausible.Event,
|
||||
where: e.name == "pageview",
|
||||
|
@ -152,6 +152,19 @@ defmodule Plausible.StatsTest do
|
||||
assert plot == [1] ++ zeroes ++ [1]
|
||||
end
|
||||
|
||||
test "displays hourly stats in configured timezone" do
|
||||
site = insert(:site, timezone: "CET") # UTC+1
|
||||
insert(:pageview, hostname: site.domain, timestamp: ~N[2019-01-01 00:00:00]) # Timestamp is in UTC
|
||||
|
||||
query = Stats.Query.from(site.timezone, %{"period" => "day", "date" => "2019-01-01"})
|
||||
|
||||
{plot, _labels, _index} = Stats.calculate_plot(site, query)
|
||||
|
||||
zeroes = Stream.repeatedly(fn -> 0 end) |> Stream.take(22) |> Enum.into([])
|
||||
|
||||
assert plot == [0, 1] ++ zeroes # Expecting pageview to show at 1am CET
|
||||
end
|
||||
|
||||
test "displays pageviews for a month" do
|
||||
site = insert(:site)
|
||||
insert(:pageview, hostname: site.domain, timestamp: ~N[2019-01-01 12:00:00])
|
||||
|
Loading…
Reference in New Issue
Block a user