From 942882806444fb55880f649514b57bef930fc92a Mon Sep 17 00:00:00 2001
From: Claudio Ortolina
Date: Sun, 5 Jan 2025 15:48:56 +0000
Subject: [PATCH] Consolidate datetime as date formatting
---
lib/music_library/records/record.ex | 2 +-
.../components/record_components.ex | 4 ++--
.../live/collection_live/show.ex | 4 ----
.../live/collection_live/show.html.heex | 6 +++---
lib/music_library_web/live/wishlist_live/show.ex | 4 ----
.../live/wishlist_live/show.html.heex | 4 ++--
.../live/collection_live/index_test.exs | 16 +++++++++-------
.../live/collection_live/show_test.exs | 10 +++-------
8 files changed, 20 insertions(+), 30 deletions(-)
diff --git a/lib/music_library/records/record.ex b/lib/music_library/records/record.ex
index c9a2bd0a..aac11bec 100644
--- a/lib/music_library/records/record.ex
+++ b/lib/music_library/records/record.ex
@@ -229,7 +229,7 @@ defmodule MusicLibrary.Records.Record do
end
end
- def format_purchased_at(purchased_at) do
+ def format_as_date(purchased_at) do
"#{purchased_at.day}/#{purchased_at.month}/#{purchased_at.year}"
end
diff --git a/lib/music_library_web/components/record_components.ex b/lib/music_library_web/components/record_components.ex
index bb2b3181..c0969dbd 100644
--- a/lib/music_library_web/components/record_components.ex
+++ b/lib/music_library_web/components/record_components.ex
@@ -66,7 +66,7 @@ defmodule MusicLibraryWeb.RecordComponents do
aria-hidden="true"
data-slot="icon"
/>
- {Records.Record.format_purchased_at(record.purchased_at)}
+ {Records.Record.format_as_date(record.purchased_at)}
@@ -90,7 +90,7 @@ defmodule MusicLibraryWeb.RecordComponents do
{gettext("Purchased on")}
<.icon name="hero-banknotes" class="-mt-1 h-4 w-4" aria-hidden="true" data-slot="icon" />
- {Records.Record.format_purchased_at(record.purchased_at)}
+ {Records.Record.format_as_date(record.purchased_at)}
<%!-- TODO: replace with OSS version --%>
diff --git a/lib/music_library_web/live/collection_live/show.ex b/lib/music_library_web/live/collection_live/show.ex
index 81fc2ae7..7ef1b336 100644
--- a/lib/music_library_web/live/collection_live/show.ex
+++ b/lib/music_library_web/live/collection_live/show.ex
@@ -138,10 +138,6 @@ defmodule MusicLibraryWeb.CollectionLive.Show do
defp title_segment(:show), do: gettext("Show")
defp title_segment(:edit), do: gettext("Edit")
- defp human_datetime(dt) do
- "#{dt.day}/#{dt.month}/#{dt.year}"
- end
-
defp toggle_actions_menu(record_id) do
JS.toggle(to: "#actions-#{record_id}")
|> JS.toggle_class("pointer-events-none", to: "#records > li")
diff --git a/lib/music_library_web/live/collection_live/show.html.heex b/lib/music_library_web/live/collection_live/show.html.heex
index 10899d89..e4aa7466 100644
--- a/lib/music_library_web/live/collection_live/show.html.heex
+++ b/lib/music_library_web/live/collection_live/show.html.heex
@@ -181,7 +181,7 @@
{gettext("Purchased on")}
- {human_datetime(@record.purchased_at)}
+ {Records.Record.format_as_date(@record.purchased_at)}
- {human_datetime(@record.inserted_at)}
+ {Records.Record.format_as_date(@record.inserted_at)}
@@ -212,7 +212,7 @@
{gettext("Updated at")}
- {human_datetime(@record.updated_at)}
+ {Records.Record.format_as_date(@record.updated_at)}
diff --git a/lib/music_library_web/live/wishlist_live/show.ex b/lib/music_library_web/live/wishlist_live/show.ex
index 57bff34e..a794f80c 100644
--- a/lib/music_library_web/live/wishlist_live/show.ex
+++ b/lib/music_library_web/live/wishlist_live/show.ex
@@ -135,10 +135,6 @@ defmodule MusicLibraryWeb.WishlistLive.Show do
defp title_segment(:show), do: gettext("Show")
defp title_segment(:edit), do: gettext("Edit")
- defp human_datetime(dt) do
- "#{dt.day}/#{dt.month}/#{dt.year}"
- end
-
defp toggle_actions_menu(record_id) do
JS.toggle(to: "#actions-#{record_id}")
|> JS.toggle_class("pointer-events-none", to: "#records > li")
diff --git a/lib/music_library_web/live/wishlist_live/show.html.heex b/lib/music_library_web/live/wishlist_live/show.html.heex
index 8e6ec3b6..5117be81 100644
--- a/lib/music_library_web/live/wishlist_live/show.html.heex
+++ b/lib/music_library_web/live/wishlist_live/show.html.heex
@@ -214,7 +214,7 @@
{gettext("Inserted at")}
- {human_datetime(@record.inserted_at)}
+ {Records.Record.format_as_date(@record.inserted_at)}
@@ -222,7 +222,7 @@
{gettext("Updated at")}
- {human_datetime(@record.updated_at)}
+ {Records.Record.format_as_date(@record.updated_at)}
diff --git a/test/music_library_web/live/collection_live/index_test.exs b/test/music_library_web/live/collection_live/index_test.exs
index d04b43b0..e08044f9 100644
--- a/test/music_library_web/live/collection_live/index_test.exs
+++ b/test/music_library_web/live/collection_live/index_test.exs
@@ -28,10 +28,6 @@ defmodule MusicLibraryWeb.CollectionLive.IndexTest do
|> Phoenix.HTML.safe_to_string()
end
- defp human_datetime(dt) do
- "#{dt.day}/#{dt.month}/#{dt.year}"
- end
-
describe "Collection" do
setup [:fill_collection, :fill_wishlist]
@@ -61,7 +57,9 @@ defmodule MusicLibraryWeb.CollectionLive.IndexTest do
|> assert_has("#records-#{record.id} p", text: record.release)
|> assert_has("#records-#{record.id} p", text: Record.format_long_label(record.format))
|> assert_has("#records-#{record.id} p", text: Record.type_long_label(record.type))
- |> assert_has("#records-#{record.id} span", text: human_datetime(record.purchased_at))
+ |> assert_has("#records-#{record.id} span",
+ text: Record.format_as_date(record.purchased_at)
+ )
for artist <- record.artists do
assert_has(session, "#records-#{record.id} a", text: escape(artist.name))
@@ -152,7 +150,9 @@ defmodule MusicLibraryWeb.CollectionLive.IndexTest do
|> assert_has("#records-#{record.id} p", text: record.release)
|> assert_has("#records-#{record.id} p", text: Record.format_long_label(record.format))
|> assert_has("#records-#{record.id} p", text: Record.type_long_label(record.type))
- |> assert_has("#records-#{record.id} span", text: human_datetime(record.purchased_at))
+ |> assert_has("#records-#{record.id} span",
+ text: Record.format_as_date(record.purchased_at)
+ )
|> unwrap(fn collection_view ->
html = render(collection_view)
assert html =~ ~p"/covers/#{record.id}?vsn=#{record.cover_hash}"
@@ -194,7 +194,9 @@ defmodule MusicLibraryWeb.CollectionLive.IndexTest do
|> assert_has("#records-#{record.id} p", text: record.release)
|> assert_has("#records-#{record.id} p", text: Record.format_long_label(record.format))
|> assert_has("#records-#{record.id} p", text: Record.type_long_label(record.type))
- |> assert_has("#records-#{record.id} span", text: human_datetime(record.purchased_at))
+ |> assert_has("#records-#{record.id} span",
+ text: Record.format_as_date(record.purchased_at)
+ )
|> unwrap(fn collection_view ->
html = render(collection_view)
assert html =~ ~p"/covers/#{record.id}?vsn=#{record.cover_hash}"
diff --git a/test/music_library_web/live/collection_live/show_test.exs b/test/music_library_web/live/collection_live/show_test.exs
index ea7e2a85..22bed68d 100644
--- a/test/music_library_web/live/collection_live/show_test.exs
+++ b/test/music_library_web/live/collection_live/show_test.exs
@@ -10,10 +10,6 @@ defmodule MusicLibraryWeb.CollectionLive.ShowTest do
|> Phoenix.HTML.safe_to_string()
end
- defp human_datetime(dt) do
- "#{dt.day}/#{dt.month}/#{dt.year}"
- end
-
describe "Edit record from show page" do
test "can navigate to the record edit form", %{conn: conn} do
record = record_fixture()
@@ -37,9 +33,9 @@ defmodule MusicLibraryWeb.CollectionLive.ShowTest do
|> assert_has("p", text: record.release)
|> assert_has("p", text: Record.format_long_label(record.format))
|> assert_has("p", text: Record.type_long_label(record.type))
- |> assert_has("dd", text: human_datetime(record.purchased_at))
- |> assert_has("dd", text: human_datetime(record.inserted_at))
- |> assert_has("dd", text: human_datetime(record.updated_at))
+ |> assert_has("dd", text: Record.format_as_date(record.purchased_at))
+ |> assert_has("dd", text: Record.format_as_date(record.inserted_at))
+ |> assert_has("dd", text: Record.format_as_date(record.updated_at))
|> unwrap(fn show_view ->
html = render(show_view)
assert html =~ ~p"/covers/#{record.id}?vsn=#{record.cover_hash}"