Fix timezone definition and handling across app
This commit is contained in:
+3
-2
@@ -15,10 +15,11 @@ config :music_library,
|
|||||||
ecto_repos: [MusicLibrary.BackgroundRepo, MusicLibrary.Repo, MusicLibrary.ErrorRepo],
|
ecto_repos: [MusicLibrary.BackgroundRepo, MusicLibrary.Repo, MusicLibrary.ErrorRepo],
|
||||||
generators: [timestamp_type: :utc_datetime, binary_id: true]
|
generators: [timestamp_type: :utc_datetime, binary_id: true]
|
||||||
|
|
||||||
|
config :music_library, timezone: "Europe/London"
|
||||||
|
|
||||||
config :music_library, MusicLibraryWeb,
|
config :music_library, MusicLibraryWeb,
|
||||||
login_password: "change me",
|
login_password: "change me",
|
||||||
api_token: "change me",
|
api_token: "change me"
|
||||||
timezone: "Europe/London"
|
|
||||||
|
|
||||||
# Configures the endpoint
|
# Configures the endpoint
|
||||||
config :music_library, MusicLibraryWeb.Endpoint,
|
config :music_library, MusicLibraryWeb.Endpoint,
|
||||||
|
|||||||
@@ -26,4 +26,6 @@ defmodule MusicLibrary do
|
|||||||
- `MusicLibrary.OnlineStoreTemplates` - Configurable templates for generating online store URLs
|
- `MusicLibrary.OnlineStoreTemplates` - Configurable templates for generating online store URLs
|
||||||
- `MusicLibrary.Secrets` - Encrypted storage for API keys and sensitive configuration
|
- `MusicLibrary.Secrets` - Encrypted storage for API keys and sensitive configuration
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
def timezone, do: Application.fetch_env!(:music_library, :timezone)
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -214,7 +214,7 @@ defmodule MusicLibrary.ScrobbleActivity do
|
|||||||
def get_top_albums_by_days(days, opts) do
|
def get_top_albums_by_days(days, opts) do
|
||||||
limit = Keyword.get(opts, :limit, 10)
|
limit = Keyword.get(opts, :limit, 10)
|
||||||
current_time = Keyword.get_lazy(opts, :current_time, &DateTime.utc_now/0)
|
current_time = Keyword.get_lazy(opts, :current_time, &DateTime.utc_now/0)
|
||||||
timezone = Keyword.get(opts, :timezone, &resolve_timezone!/0)
|
timezone = Keyword.get(opts, :timezone, &MusicLibrary.timezone/0)
|
||||||
|
|
||||||
cutoff_timestamp =
|
cutoff_timestamp =
|
||||||
current_time
|
current_time
|
||||||
@@ -304,7 +304,7 @@ defmodule MusicLibrary.ScrobbleActivity do
|
|||||||
def get_top_artists_by_days(days, opts) do
|
def get_top_artists_by_days(days, opts) do
|
||||||
limit = Keyword.get(opts, :limit, 10)
|
limit = Keyword.get(opts, :limit, 10)
|
||||||
current_time = Keyword.get_lazy(opts, :current_time, &DateTime.utc_now/0)
|
current_time = Keyword.get_lazy(opts, :current_time, &DateTime.utc_now/0)
|
||||||
timezone = Keyword.get(opts, :timezone, &resolve_timezone!/0)
|
timezone = Keyword.get(opts, :timezone, &MusicLibrary.timezone/0)
|
||||||
|
|
||||||
cutoff_timestamp =
|
cutoff_timestamp =
|
||||||
current_time
|
current_time
|
||||||
@@ -376,9 +376,4 @@ defmodule MusicLibrary.ScrobbleActivity do
|
|||||||
:last_365_days -> get_top_artists_by_days(365, opts)
|
:last_365_days -> get_top_artists_by_days(365, opts)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
defp resolve_timezone! do
|
|
||||||
Application.get_env(:music_library, MusicLibraryWeb)
|
|
||||||
|> Keyword.fetch!(:timezone)
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -25,7 +25,7 @@ defmodule MusicLibraryWeb.CollectionLive.Show do
|
|||||||
{:ok,
|
{:ok,
|
||||||
socket
|
socket
|
||||||
|> assign(:current_section, :collection)
|
|> assign(:current_section, :collection)
|
||||||
|> assign(:timezone, resolve_timezone!())
|
|> assign(:timezone, MusicLibrary.timezone())
|
||||||
|> assign(:can_scrobble?, ScrobbleActivity.can_scrobble?())
|
|> assign(:can_scrobble?, ScrobbleActivity.can_scrobble?())
|
||||||
|> assign(:release_with_tracks, nil)}
|
|> assign(:release_with_tracks, nil)}
|
||||||
end
|
end
|
||||||
@@ -182,9 +182,4 @@ defmodule MusicLibraryWeb.CollectionLive.Show do
|
|||||||
|
|
||||||
defp title_segment(:show), do: gettext("Show")
|
defp title_segment(:show), do: gettext("Show")
|
||||||
defp title_segment(:edit), do: gettext("Edit")
|
defp title_segment(:edit), do: gettext("Edit")
|
||||||
|
|
||||||
defp resolve_timezone! do
|
|
||||||
Application.get_env(:music_library, MusicLibraryWeb)
|
|
||||||
|> Keyword.fetch!(:timezone)
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -23,7 +23,7 @@ defmodule MusicLibraryWeb.StatsLive.Index do
|
|||||||
|
|
||||||
{:ok,
|
{:ok,
|
||||||
socket
|
socket
|
||||||
|> assign(:timezone, resolve_timezone!())
|
|> assign(:timezone, MusicLibrary.timezone())
|
||||||
|> stream_configure(:recent_tracks,
|
|> stream_configure(:recent_tracks,
|
||||||
dom_id: fn track -> "track-#{track.scrobbled_at_uts}" end
|
dom_id: fn track -> "track-#{track.scrobbled_at_uts}" end
|
||||||
)
|
)
|
||||||
@@ -160,9 +160,4 @@ defmodule MusicLibraryWeb.StatsLive.Index do
|
|||||||
|> DateTime.from_unix!()
|
|> DateTime.from_unix!()
|
||||||
|> DateTime.to_iso8601()
|
|> DateTime.to_iso8601()
|
||||||
end
|
end
|
||||||
|
|
||||||
defp resolve_timezone! do
|
|
||||||
Application.get_env(:music_library, MusicLibraryWeb)
|
|
||||||
|> Keyword.fetch!(:timezone)
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user