Skip to content

Commit

Permalink
fix(Credo): Remove negated check in if-else (#2055)
Browse files Browse the repository at this point in the history
* fix(Credo): Remove negated check in if-else

* Responded to feedback
  • Loading branch information
kotva006 authored May 15, 2024
1 parent 5885848 commit d1483e6
Showing 1 changed file with 13 additions and 11 deletions.
24 changes: 13 additions & 11 deletions lib/schedules/hours_of_operation.ex
Original file line number Diff line number Diff line change
Expand Up @@ -156,19 +156,21 @@ defmodule Schedules.HoursOfOperation do
end

defp get_valid_day(check_date, days_to_avoid) do
if !Enum.member?(days_to_avoid, check_date) do
check_date
if Enum.member?(days_to_avoid, check_date) do
next_date = get_next_date(check_date)
get_valid_day(next_date, days_to_avoid)
else
next_date =
case Date.day_of_week(check_date) do
d when d in 1..4 -> Date.add(check_date, 1)
# Friday so skip weekend to Monday
5 -> Date.add(check_date, 3)
# Saturday or Sunday so jump to next weeks Sat or Sun
_ -> Date.add(check_date, 7)
end
check_date
end
end

get_valid_day(next_date, days_to_avoid)
defp get_next_date(check_date) do
case Date.day_of_week(check_date) do
d when d in 1..4 -> Date.add(check_date, 1)
# Friday so skip weekend to Monday
5 -> Date.add(check_date, 3)
# Saturday or Sunday so jump to next weeks Sat or Sun
_ -> Date.add(check_date, 7)
end
end

Expand Down

0 comments on commit d1483e6

Please sign in to comment.