Skip to content

Commit

Permalink
Improved error messaging
Browse files Browse the repository at this point in the history
  • Loading branch information
corka149 committed Mar 8, 2020
1 parent 6c4a399 commit 6443196
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions lib/cli.ex
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,10 @@ defmodule Timed.Cli do

defp is_valid_date?(date: date) do
{result, _} = Date.from_iso8601(date)

unless :ok == result do
Log.error("Invalid date format.")
end
:ok == result
end

Expand All @@ -121,9 +125,16 @@ defmodule Timed.Cli do

defp is_valid_time?(args) do
[start_t, end_t] = Timed.parse_time(args)
{result_start, _} = Time.from_iso8601("#{start_t}:00")
{result_end, _} = Time.from_iso8601("#{end_t}:00")
(:ok == result_start or start_t == "") and (:ok == result_end or end_t == "")

check = fn time, type ->
{result, _} = Time.from_iso8601("#{time}:00")
unless :ok == result do
Log.error("Invalid time format for #{type} time.")
end
:ok == result
end

(check.(start_t, "starting") or start_t == "") and (check.(end_t, "ending") or end_t == "")
end

defp date_arg({aliases, strict}) do
Expand Down

0 comments on commit 6443196

Please sign in to comment.