     end
   end
 
-  defp substract_days(date, days) do
-    :calendar.gregorian_days_to_date(
-      :calendar.date_to_gregorian_days(date) - days
-    )
-  end
-
-  defp current_date do
-    {date, _time} = :calendar.local_time()
-
-    date
-  end
-
   defp date_to_string(date) do
-    Tuple.to_list(date) |> Enum.join("-")
+    {:ok, str_date} = Timex.DateFormat.format(date, "%Y-%m-%d", :strftime)
+    str_date
   end
 
   defp find_last_transaction(saltedge_account_id) do

    case fetch_custom(saltedge_account_id, from, to, nil, []) do
      [] -> List.flatten(acc)
      transactions_chunk ->
        to = substract_days(from, 30)
        from = substract_days(from, 1)
        fetch_all(saltedge_account_id, from, to, [transactions_chunk | acc])
    end
  end


  end

  defp fetch_all(saltedge_account_id) do
    to = Timex.Date.local
    from = Timex.Date.shift(to, months: -1)

    transactions = fetch_all(saltedge_account_id, from, to, [])

