feat: display due date better
This commit is contained in:
parent
af1e2eb06f
commit
a59ad17743
1 changed files with 34 additions and 1 deletions
|
|
@ -20,7 +20,7 @@ defmodule PutzplanWeb.TaskLive.Index do
|
|||
>
|
||||
<:col :let={{_id, task}} label="Description">{task.description}</:col>
|
||||
|
||||
<:col :let={{_id, task}} label="Due">{task.due}</:col>
|
||||
<:col :let={{_id, task}} label="Due">{format_date(task.due)}</:col>
|
||||
|
||||
<:action :let={{_id, task}}>
|
||||
<div class="sr-only">
|
||||
|
|
@ -115,4 +115,37 @@ defmodule PutzplanWeb.TaskLive.Index do
|
|||
|
||||
{:noreply, stream_insert(socket, :tasks, Ash.get!(Putzplan.Tasks.Task, id, load: [:due]))}
|
||||
end
|
||||
|
||||
defp format_date(date) do
|
||||
string =
|
||||
case Date.diff(date, Date.utc_today()) do
|
||||
0 ->
|
||||
"today"
|
||||
|
||||
1 ->
|
||||
"tomorrow"
|
||||
|
||||
days when days > 0 and days < 7 ->
|
||||
"next " <> get_weekday(Date.day_of_week(date))
|
||||
|
||||
_ ->
|
||||
Date.to_string(date)
|
||||
end
|
||||
|
||||
String.capitalize(string)
|
||||
end
|
||||
|
||||
defp get_weekday(index) do
|
||||
days = %{
|
||||
1 => "monday",
|
||||
2 => "tuesday",
|
||||
3 => "wednesday",
|
||||
4 => "thursday",
|
||||
5 => "friday",
|
||||
6 => "saturday",
|
||||
7 => "sunday"
|
||||
}
|
||||
|
||||
Map.get(days, index)
|
||||
end
|
||||
end
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue