Show how many years ago for "On this day" records

This commit is contained in:
Claudio Ortolina
2025-08-29 13:09:27 +03:00
parent e54dcc50dc
commit 064ece03f3
7 changed files with 40 additions and 9 deletions
+15
View File
@@ -82,6 +82,21 @@ defmodule MusicLibrary.Records.Record do
end
end
def released_how_long_ago?(%{release_date: nil}, _current_day), do: nil
def released_how_long_ago?(record, current_day) do
case Date.from_iso8601(record.release_date) do
{:ok, release_date} ->
# approximate calculation of "how many years ago",
# we don't really care about leap years
diff_days = Date.diff(current_day, release_date)
div(diff_days, 365)
_error ->
nil
end
end
def releases(record) do
record.musicbrainz_data
|> ReleaseGroup.releases()