Fix timezone definition and handling across app

This commit is contained in:
Claudio Ortolina
2025-09-11 16:17:20 +03:00
parent 5aaa7708ee
commit c67fd27ea1
5 changed files with 9 additions and 21 deletions
+3 -2
View File
@@ -15,10 +15,11 @@ config :music_library,
ecto_repos: [MusicLibrary.BackgroundRepo, MusicLibrary.Repo, MusicLibrary.ErrorRepo],
generators: [timestamp_type: :utc_datetime, binary_id: true]
config :music_library, timezone: "Europe/London"
config :music_library, MusicLibraryWeb,
login_password: "change me",
api_token: "change me",
timezone: "Europe/London"
api_token: "change me"
# Configures the endpoint
config :music_library, MusicLibraryWeb.Endpoint,
+2
View File
@@ -26,4 +26,6 @@ defmodule MusicLibrary do
- `MusicLibrary.OnlineStoreTemplates` - Configurable templates for generating online store URLs
- `MusicLibrary.Secrets` - Encrypted storage for API keys and sensitive configuration
"""
def timezone, do: Application.fetch_env!(:music_library, :timezone)
end
+2 -7
View File
@@ -214,7 +214,7 @@ defmodule MusicLibrary.ScrobbleActivity do
def get_top_albums_by_days(days, opts) do
limit = Keyword.get(opts, :limit, 10)
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 =
current_time
@@ -304,7 +304,7 @@ defmodule MusicLibrary.ScrobbleActivity do
def get_top_artists_by_days(days, opts) do
limit = Keyword.get(opts, :limit, 10)
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 =
current_time
@@ -376,9 +376,4 @@ defmodule MusicLibrary.ScrobbleActivity do
:last_365_days -> get_top_artists_by_days(365, opts)
end
end
defp resolve_timezone! do
Application.get_env(:music_library, MusicLibraryWeb)
|> Keyword.fetch!(:timezone)
end
end
@@ -25,7 +25,7 @@ defmodule MusicLibraryWeb.CollectionLive.Show do
{:ok,
socket
|> assign(:current_section, :collection)
|> assign(:timezone, resolve_timezone!())
|> assign(:timezone, MusicLibrary.timezone())
|> assign(:can_scrobble?, ScrobbleActivity.can_scrobble?())
|> assign(:release_with_tracks, nil)}
end
@@ -182,9 +182,4 @@ defmodule MusicLibraryWeb.CollectionLive.Show do
defp title_segment(:show), do: gettext("Show")
defp title_segment(:edit), do: gettext("Edit")
defp resolve_timezone! do
Application.get_env(:music_library, MusicLibraryWeb)
|> Keyword.fetch!(:timezone)
end
end
@@ -23,7 +23,7 @@ defmodule MusicLibraryWeb.StatsLive.Index do
{:ok,
socket
|> assign(:timezone, resolve_timezone!())
|> assign(:timezone, MusicLibrary.timezone())
|> stream_configure(:recent_tracks,
dom_id: fn track -> "track-#{track.scrobbled_at_uts}" end
)
@@ -160,9 +160,4 @@ defmodule MusicLibraryWeb.StatsLive.Index do
|> DateTime.from_unix!()
|> DateTime.to_iso8601()
end
defp resolve_timezone! do
Application.get_env(:music_library, MusicLibraryWeb)
|> Keyword.fetch!(:timezone)
end
end