Skip to content

Commit

Permalink
Fix
Browse files Browse the repository at this point in the history
  • Loading branch information
solar05 committed Nov 18, 2023
1 parent c26e6c2 commit ece8d66
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions modules/65-extra/10-dates-and-times/lib/solution.ex
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,23 @@ defmodule Solution do
def shift_days(time, 0), do: time

def shift_days(%Time{} = time, amount) when is_integer(amount) do
Time.add(time, amount * 24, :hour)
Time.add(time, days_to_seconds(amount) * 24, :second)
end

def shift_days(%NaiveDateTime{} = time, amount) when is_integer(amount) do
NaiveDateTime.add(time, amount, :day)
NaiveDateTime.add(time, days_to_seconds(amount), :second)
end

def shift_days(%Date{} = time, amount) when is_integer(amount) do
Date.add(time, amount)
end

def shift_days(%DateTime{} = time, amount) when is_integer(amount) do
DateTime.add(time, amount, :day)
DateTime.add(time, days_to_seconds(amount), :second)
end

defp days_to_seconds(amount) do
amount * 24 * 60 * 60
end

# END
Expand Down

0 comments on commit ece8d66

Please sign in to comment.