improvements including removing Timex library
This commit is contained in:
parent
ab11131df6
commit
686db55e8b
18 changed files with 179 additions and 149 deletions
lib/shift73k
|
@ -26,8 +26,15 @@ defmodule Shift73k.Shifts do
|
|||
|> where([s], s.user_id == ^user_id)
|
||||
end
|
||||
|
||||
def list_shifts_by_user(user_id) do
|
||||
user_id
|
||||
|> query_shifts_by_user()
|
||||
|> Repo.all()
|
||||
end
|
||||
|
||||
def list_shifts_by_user_in_date_range(user_id, %Date.Range{} = date_range) do
|
||||
query_shifts_by_user(user_id)
|
||||
user_id
|
||||
|> query_shifts_by_user()
|
||||
|> where([s], s.date >= ^date_range.first)
|
||||
|> where([s], s.date <= ^date_range.last)
|
||||
|> order_by([s], [s.date, s.time_start])
|
||||
|
@ -35,12 +42,14 @@ defmodule Shift73k.Shifts do
|
|||
end
|
||||
|
||||
defp query_shifts_by_user_from_list_of_dates(user_id, date_list) do
|
||||
query_shifts_by_user(user_id)
|
||||
user_id
|
||||
|> query_shifts_by_user()
|
||||
|> where([s], s.date in ^date_list)
|
||||
end
|
||||
|
||||
def list_shifts_by_user_from_list_of_dates(user_id, date_list) do
|
||||
query_shifts_by_user_from_list_of_dates(user_id, date_list)
|
||||
user_id
|
||||
|> query_shifts_by_user_from_list_of_dates(date_list)
|
||||
|> Repo.all()
|
||||
end
|
||||
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
defmodule Shift73k.Shifts.Templates.ShiftTemplate do
|
||||
use Timex
|
||||
use Ecto.Schema
|
||||
import Ecto.Changeset
|
||||
|
||||
|
@ -59,7 +58,7 @@ defmodule Shift73k.Shifts.Templates.ShiftTemplate do
|
|||
[]
|
||||
end
|
||||
end)
|
||||
|> validate_inclusion(:time_zone, Timex.timezones(),
|
||||
|> validate_inclusion(:time_zone, Tzdata.zone_list(),
|
||||
message: "must be a valid IANA tz database time zone"
|
||||
)
|
||||
end
|
||||
|
@ -70,7 +69,8 @@ defmodule Shift73k.Shifts.Templates.ShiftTemplate do
|
|||
|
||||
def shift_length(%ShiftTemplate{time_end: time_end, time_start: time_start}) do
|
||||
time_end
|
||||
|> Timex.diff(time_start, :minute)
|
||||
|> Time.diff(time_start)
|
||||
|> Integer.floor_div(60)
|
||||
|> shift_length()
|
||||
end
|
||||
|
||||
|
@ -79,11 +79,4 @@ defmodule Shift73k.Shifts.Templates.ShiftTemplate do
|
|||
|
||||
def shift_length(time_end, time_start),
|
||||
do: shift_length(%ShiftTemplate{time_end: time_end, time_start: time_start})
|
||||
|
||||
def shift_length_h_m(%ShiftTemplate{time_end: _, time_start: _} = template) do
|
||||
shift_length_seconds = shift_length(template)
|
||||
h = shift_length_seconds |> Integer.floor_div(60)
|
||||
m = shift_length_seconds |> rem(60)
|
||||
{h, m}
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue