From 529d4f301800f19aab4de172f9ec843af077619d Mon Sep 17 00:00:00 2001 From: Uku Taht Date: Thu, 21 Nov 2019 16:59:06 +0800 Subject: [PATCH] Fix offset in react --- assets/js/dashboard/date.js | 5 +++-- lib/plausible_web/controllers/site_controller.ex | 5 ++++- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/assets/js/dashboard/date.js b/assets/js/dashboard/date.js index 0bbf0f9fb..86f8e5406 100644 --- a/assets/js/dashboard/date.js +++ b/assets/js/dashboard/date.js @@ -37,8 +37,9 @@ export function formatDay(date) { } // https://stackoverflow.com/a/11124448 -export function newDateInOffset(offset) { - return new Date(new Date().getTime() + offset * 1000) +export function newDateInOffset(siteOffset) { + const browserOffset = (new Date()).getTimezoneOffset() * 60 + return new Date(new Date().getTime() + (siteOffset * 1000) + (browserOffset * 1000)) } export function isToday(site, date) { diff --git a/lib/plausible_web/controllers/site_controller.ex b/lib/plausible_web/controllers/site_controller.ex index 53aef9011..6ac028e55 100644 --- a/lib/plausible_web/controllers/site_controller.ex +++ b/lib/plausible_web/controllers/site_controller.ex @@ -124,12 +124,15 @@ defmodule PlausibleWeb.SiteController do def update_settings(conn, %{"website" => website, "site" => site_params}) do site = Sites.get_for_user!(conn.assigns[:current_user].id, website) - changeset = site |> Plausible.Site.changeset(site_params) + changeset = site |> Plausible.Site.changeset(site_params) res = changeset |> Repo.update case res do {:ok, site} -> + site_session_key = "authorized_site__" <> site.domain + conn + |> put_session(site_session_key, nil) |> put_flash(:success, "Site settings saved succesfully") |> redirect(to: "/#{site.domain}/settings") {:error, changeset} ->