From 3af6b65e83720a856574edc28e77c6135ca10576 Mon Sep 17 00:00:00 2001 From: Aayush Kumar Sahu Date: Fri, 24 May 2024 23:19:45 +0530 Subject: [PATCH] notes: show day of the week along with dates --- lib/accumulator/helpers.ex | 8 ++++++++ lib/accumulator_web/live/notes_live/notes_live.html.heex | 6 ++++-- lib/accumulator_web/live/notes_live/notes_public_live.ex | 6 ++++-- 3 files changed, 16 insertions(+), 4 deletions(-) diff --git a/lib/accumulator/helpers.ex b/lib/accumulator/helpers.ex index 952d95a..31aa26f 100644 --- a/lib/accumulator/helpers.ex +++ b/lib/accumulator/helpers.ex @@ -38,4 +38,12 @@ defmodule Accumulator.Helpers do |> NaiveDateTime.add(1, :day) |> DateTime.from_naive!("Etc/UTC") end + + def day_of_week_string(date_string) do + day = Date.from_iso8601!(date_string) |> Date.day_of_week() + index = day - 1 + + ["Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"] + |> Enum.at(index) + end end diff --git a/lib/accumulator_web/live/notes_live/notes_live.html.heex b/lib/accumulator_web/live/notes_live/notes_live.html.heex index 7e00a99..767171e 100644 --- a/lib/accumulator_web/live/notes_live/notes_live.html.heex +++ b/lib/accumulator_web/live/notes_live/notes_live.html.heex @@ -102,7 +102,9 @@ >
- <%= date %> (<%= Accumulator.Helpers.days_ago(date) %>) + <%= Accumulator.Helpers.day_of_week_string(date) %> <%= date %> (<%= Accumulator.Helpers.days_ago( + date + ) %>)
@@ -111,7 +113,7 @@
- <.local_time id={"note-#{note.id}-date"} date={note.updated_at} /> + <.local_time id={"note-#{note.id}-date"} date={note.inserted_at} />