Skip to content

Instantly share code, notes, and snippets.

@bglusman
Last active January 5, 2017 16:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bglusman/ef121631b9c7e77fd7dc553514e0ebbe to your computer and use it in GitHub Desktop.
Save bglusman/ef121631b9c7e77fd7dc553514e0ebbe to your computer and use it in GitHub Desktop.
date_string_or_error attempt, not working
def modified_date_or_datetime(string, modifier) do
date_match = Date.from_iso8601(string)
iso_match = Timex.parse(string, "{ISO:Extended}")
isoz_match = Timex.parse(string, "{ISO:Extended:Z}")
case {:ok, x } do
^date_match -> "#{string}#{modifier}"
^iso_match -> string
^isoz_match -> string
_ -> raise "Invalid ISO8601 date/datetime format provided: #{string}"
end
end
def modified_date_or_datetime(string, modifier) do
cond do
{:ok, _parsed_date} = Date.from_iso8601(string) -> "#{string}#{modifier}"
{:ok, _parsed_datetime} = Timex.parse(string, "{ISO:Extended}") -> string
{:ok, _parsed_datetime} = Timex.parse(string, "{ISO:Extended:Z}") -> string
true -> raise "Invalid ISO8601 date/datetime format provided: #{string}"
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment